Tag: compiler errors

不可调用的成员”不能像方法一样使用

我正面临着一个问题。 所以我会马上放置代码; public static List blockedOpcodes = new List(); public static bool isOpcodeAllowed(ushort opcode) { lock (locker) { if (blockedOpcodes.Contains(opcode)) { Log1.LogMsg(“Oops! Someone tried to send a blocked packet: 0x{” + opcode + “:X}”); return false; } return true; } } public static void Load() { lock (locker) { StreamReader reader; using (reader = new […]

错误:必须在控制离开当前方法之前分配Out参数

发回参数时会收到此错误 错误:必须在控制离开当前方法之前分配Out参数 代码是 public void GetPapers(string web, out int Id1, out int Id2) { SqlConnection conn = new SqlConnection(ConnectionString()); conn.Open(); SqlCommand cmd = new SqlCommand(“GetPapers”, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter(“@URL”, String(web))); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.Read()) { Id1 = (int)rdr[“ID1”]; Id2 = (int)rdr[“ID2”]; } rdr.Close(); } 称之为 GetPapers(web, out Id1, out Id2); 与此问题相关 […]

为什么我可以通过索引访问KeyCollection / ValueCollection中的项目,即使它没有实现IList(Of Key)?

我注意到一个奇怪的VB.NET事情。 从这个问题来看,我提供了一种方法来通过索引来访问字典的KeysCollection和ValuesCollection键和值,以获得第一项。 我知道它只在SortedDictionary有意义,因为普通的Dictionary 没有被排序 (好吧,你不应该依赖它的顺序)。 这是一个简单的例子: Dim sortedDict As New SortedDictionary(Of DateTime, String) sortedDict.Add(DateTime.Now, “Foo”) Dim keys As SortedDictionary(Of DateTime, String).KeyCollection = sortedDict.Keys Dim values As SortedDictionary(Of DateTime, String).ValueCollection = sortedDict.Values Dim firstkey As DateTime = keys(0) Dim firstValue As String = values(0) 但我很惊讶这个问题的提问者说它没有编译,而它编译并且对我有用而没有问题: System.Diagnostics.Debug.WriteLine(“Key:{0} Value:{1}”, firstkey, firstValue) ‘ Key:04/29/2016 10:15:23 Value:Foo 那么为什么我可以使用它,就像有一个索引器,如果在SortedDictionary(Of TKey, TValue).KeyCollection没有实际的一个SortedDictionary(Of […]

导致“扩展方法无法动态调度”的原因在这里?

编译错误 ‘System.Data.SqlClient.SqlConnection’没有名为’Query’的适用方法,但似乎有一个名称的扩展方法。 无法动态分派扩展方法。 考虑转换动态参数或调用扩展方法而不使用扩展方法语法。 现在,我知道如何解决这个问题,但我正在努力更好地理解错误本身。 我正在上课,以利用Dapper。 最后,我将提供一些更多自定义function,以使我们的数据访问类型更加简化。 特别是在追踪和东西的建设。 但是,现在它就像这样简单: public class Connection : IDisposable { private SqlConnection _connection; public Connection() { var connectionString = Convert.ToString(ConfigurationManager.ConnectionStrings[“ConnectionString”]); _connection = new SqlConnection(connectionString); _connection.Open(); } public void Dispose() { _connection.Close(); _connection.Dispose(); } public IEnumerable Query(string sql, dynamic param = null, IDbTransaction transaction = null, bool buffered = true, int? […]