有一个结构:
public struct ReturnedCommands
{
public string key;
public string command;
};
Run Code Online (Sandbox Code Playgroud)
......和一个变量:
public static ReturnedCommands returnedCommands;
Run Code Online (Sandbox Code Playgroud)
...并且发生Null Reference Exception,返回值"3":
public bool PendingCommandsExecute_QUERY()
{
int i = 0;
try
{
i = 1;
cmdResults b = cmdResults.cmdFail;
bool retVal = false;
string command = "QUERY";
if (returnedCommands.key != command)
return false;
HashResultsAdd(command, "Started");
i = 2;
HashStatus.Clear();
string sNum = PendingCommands.SiteFetchSiteNumber;
i = 3; // <-- last one reached (debug int displayed in NRE)
string s = string.Empty;
if (returnedCommands.command …Run Code Online (Sandbox Code Playgroud) 此方法是Windows CE/CF/.NET1.1项目的一部分:
public void createSettingsTable()
{
public string filename = "\\my documents\\CCRDB.SDF";
string conStr = "Data Source = " + filename;
try
{
using (SqlCeConnection con = new SqlCeConnection(conStr)
{
con.Open();
using (SqlCeCommand com = new SqlCeCommand("create table ccr_settings (setting_id INT IDENTITY NOT NULL PRIMARY KEY, setting_name varchar(40) not null, setting_value(63) varchar not null)", con))
{
com.ExecuteNonQuery();
}
con.Close();
}
}
catch (Exception ex)
{
CCR.ExceptionHandler(ex, "createSettingsTable");
}
}
Run Code Online (Sandbox Code Playgroud)
...似乎被编译器视为完全陌生的东西.以下是粘贴它时导致的错误消息列表:

我在我正在维护的实用程序上运行代码分析,它建议我更改它:
private static extern int ReadMenu1File(string Menu1Path);
Run Code Online (Sandbox Code Playgroud)
......对此:
private static extern int ReadMenu1File(UnmanagedType.LPWStr Menu1Path);
Run Code Online (Sandbox Code Playgroud)
...使用此措辞:"为P/Invoke字符串参数指定封送处理为了降低安全风险,将参数'Menu1Path'编组为Unicode,将DllImport.CharSet设置为CharSet.Unicode,或者将参数显式封送为UnmanagedType.LPWStr.如果需要将此字符串封装为ANSI或依赖于系统,请明确指定MarshalAs,并设置BestFitMapping = false;为了增加安全性,还要设置ThrowOnUnmappableChar = true."
...但是当我这样做时,它说:" 类型名称'LPWStr'在类型'System.Runtime.InteropServices.UnmanagedType'中不存在 "和''System.Runtime.InteropServices.UnmanagedType.LPWStr'是'字段'但用作'类型' "
代码完成没有帮助(键入"UnmanagedType."后没有建议.)也没有上下文菜单选项来添加缺失使用.
ASP.NET Webforms项目有一些默认页面("About"和"Contact"是特定的),它们具有以下类型的内容:
<%@ Page Title="About" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="About.aspx.cs" Inherits="About" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<h2><%: Title %>.</h2>
<h3>Your application description page.</h3>
<p>Use this area to provide additional information.</p>
</asp:Content>
Run Code Online (Sandbox Code Playgroud)
然而,当您选择添加> Web窗体时,它会创建:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DuckbilledPlatypus.aspx.cs" Inherits="DuckbilledPlatypus" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
为什么差异/不一致?注意:这是在Visual Studio 2013中; 我不肯定其他版本是相同的.
我不是在谈论吸血蜘蛛般的疾病传播者,而是我在这里记录的那种滴答:
Stopwatch noLyme = new Stopwatch();
noLyme.Start();
. . .
noLyme.Stop();
MessageBox.Show(string.Format(
"elapsed milliseconds == {0}, elapsed ticks == {1}",
noLyme.ElapsedMilliseconds, noLyme.ElapsedTicks));
Run Code Online (Sandbox Code Playgroud)
消息框显示的是17357毫秒和56411802滴答; 这相当于每毫秒3250.089416373797个刻度,或每秒约325万个刻度.
由于比率是如此奇怪(3250.089416373797:1),我假设刻度的时间长度根据使用的硬件或其他因素而变化.既然如此,实际使用的是滴答计数?对我来说,似乎毫秒有更多的价值.IOW:为什么我会关心滴答声(可变时间片)?
这个LINQ:
public IEnumerable<InventoryItem> GetDepartmentRange(double deptBegin, double deptEnd)
{
// Break the doubles into their component parts:
int deptStartWhole = (int)Math.Truncate(deptBegin);
int startFraction = (int)((deptBegin - deptStartWhole) * 100);
int deptEndWhole = (int)Math.Truncate(deptEnd);
int endFraction = (int)((deptBegin - deptEndWhole) * 100);
return inventoryItems.Where(d => d.dept >= deptStartWhole).Where(e => e.subdept >= startFraction)
.Where(f => f.dept <= deptEndWhole)
.Where(g => g.subdept >= endFraction)
.OrderBy(o => o.dept)
.OrderBy(s => s.subdept);
}
Run Code Online (Sandbox Code Playgroud)
...当我输入时返回预期的数据:
http://localhost:28642/api/inventoryitems/GetDeptRange/1.1/79.99/
Run Code Online (Sandbox Code Playgroud)
...即(子集):
<InventoryItem>
<Description>LID - Blank & Ten PLU</Description>
<ID>110</ID>
<OpenQty>0</OpenQty>
<UPC>110</UPC> …Run Code Online (Sandbox Code Playgroud) 我认为它会是这样的(伪代码):
var pars = new List<string>();
string par;
while (not eof("Platypus.html"))
{
par = getNextParagraph();
pars.Add(par);
}
Run Code Online (Sandbox Code Playgroud)
... getNextParagraph() 查找下一个"<p>"并继续,直到找到"</p>",烧毁其后面的桥梁(“剪切”该段落,以便不会一遍又一遍地找到它)。或者一些这样的。
有人知道如何准确地做到这一点/更好的方法吗?
我尝试使用 Aurelien Souchet 的代码。
我有以下用途:
using HtmlAgilityPack;
using HtmlDocument = System.Windows.Forms.HtmlDocument;
Run Code Online (Sandbox Code Playgroud)
...但是这段代码:
HtmlDocument doc = new HtmlDocument();
Run Code Online (Sandbox Code Playgroud)
是不需要的(“此处无法访问私有构造函数'HtmlDocument' ”)
此外,“doc.LoadHtml()”和“doc.DocumentNode”都给出了旧的“无法解析符号'Bla'”错误消息
好吧,我必须在前面加上“HtmlAgilityPack”。从而消除了含糊的参考。
我得到,“找不到类型或命名空间名称‘INRBQDeliveryRepository’(您是否缺少 using 指令或程序集引用?)”在这里:
public class DeliveryController : ApiController
{
private readonly INRBQDeliveryRepository _deliveryRepository;
Run Code Online (Sandbox Code Playgroud)
我试图引用的接口类型是:
namespace SeaStore.Data.Legacy.Interfaces
{
public interface INRBQDeliveryRepository
. . .
Run Code Online (Sandbox Code Playgroud)
这些是解决方案中的不同项目(NRBQ.Web 正在尝试访问其兄弟 SeaStore.Data.Legacy);添加“使用 SeaStore.Data.Legacy.Interfaces;” 使用“未找到”错误阻止编译的类没有帮助 - 事实上,我从上面提到的错误转到获得附加错误,特别是:
“类型或命名空间名称 'Data' 在命名空间 'SeaStore' 中不存在(您是否缺少程序集引用?) ”在此处的 Controller 类中:
using SeaStore.Data.Legacy.Interfaces;
Run Code Online (Sandbox Code Playgroud)
为什么我的其他项目界面不可见?
我有一些有时可以工作的异步代码,有时却没有.使用此代码,始终会创建文件,但有时它是空的(我总是发送包含内容的文件):
[HttpPost]
[Route("api/inventory/sendxml/{userId}/{pwd}/{filename}")]
public async void SendInventoryXML(String userId, String pwd, String fileName)
{
Task task = Request.Content.ReadAsStreamAsync().ContinueWith(t =>
{
var stream = t.Result;
using (FileStream fileStream = File.Create(String.Format(@"C:\HDP\{0}.xml", fileName), (int)stream.Length))
{
byte[] bytesInStream = new byte[stream.Length];
stream.Read(bytesInStream, 0, (int)bytesInStream.Length);
fileStream.Write(bytesInStream, 0, bytesInStream.Length);
}
});
}
Run Code Online (Sandbox Code Playgroud)
那么,我是否应该取消同步这个随机工作的代码,如果是的话,如何(如果没有不同步的变幻无常的事情(假设是导致这种随机行为的问题)将会完成同样的事情)?
我有这个代码来从SQLite表中获取计数:
internal static bool TableExistsAndIsNotEmpty(string tableName)
{
int count;
string qry = String.Format("SELECT COUNT(*) FROM {0}", tableName);
using (SQLiteConnection con = new SQLiteConnection(HHSUtils.GetDBConnection()))
{
con.Open();
SQLiteCommand cmd = new SQLiteCommand(qry, con);
count = (int)cmd.ExecuteScalar();
}
return count > 0;
}
Run Code Online (Sandbox Code Playgroud)
当它运行时,我得到" 无效的强制转换异常 "
很明显,从查询返回的值是一个int,也就是记录的数量(我运行查询时得到"2",即Sqlite浏览器中的"SELECT COUNT(*)FROM WorkTables") .
那么在这里被无效投入的是什么?
作为一种旁注,我知道最好使用查询参数,我在这里找到了如何在Windows应用商店中执行此操作[ 如何在WinRT应用中使用SQLite查询参数?,但不知道如何在一个旧的(Windows窗体/ Windows CE)应用程序中执行此操作.
我认为会是这样的:
string qry = "SELECT COUNT(*) FROM ?";
using (SQLiteConnection con = new SQLiteConnection(HHSUtils.GetDBConnection()))
{
con.Open();
SQLiteCommand cmd = new SQLiteCommand(con);
count = cmd.ExecuteScalar(qry, tableName);
}
Run Code Online (Sandbox Code Playgroud)
......但我尝试编译的类似之处.