在VB.Net中使用lambda会导致无智能感知。这是VS2010或预期的错误吗?请注意,它在C#
中工作正常Return Array.TrueForAll(chequeColl, Function(x) x.Number <> "N") 'No intellisense Number does not appear
Return Array.TrueForAll(chequeColl, Function(x As MyClass) x.Number <> "N") 'Now casted intellisense appears
更新:这是一个例子
Public Class Cheque
Public Property Id As String
Public Property Status As Byte
Public Property Amount As String
Public Property Number As String
End Class
Public Class ChequeCollection
Private chequeColl() As Cheque
Public Sub DoStuff()
Array.TrueForAll(chequeColl, Function(x As Cheque) x.Number = 1) 'x has to be cast as cheque for intellisense to appear
End Sub
End Class
答案 0 :(得分:1)
对象数组的强类型不像List(Of T)类那样。所以当你输入'x'时。并且期望“数字”出现在Intellisese中,它不会。运行时不知道该数组中的对象类型。
如果您选择这样做,您可以使用LINQ将该数组转换为强大的对象集合,然后然后显示Intellisense。以下行应该正常工作:
Dim ChequeList =(来自c在MyArrayOfObjects中选择c).ToList()
另外还有一件事要检查VB.NET与C#intellisense。 'Option Infer'必须打开'On'。它默认为 ,但不适用于升级后的项目(即从05 - > 08 - > 10升级)
为什么我的Lambda函数在运行时因System.MissingMemberException异常而出错?
http://allen-conway-dotnet.blogspot.com/2010/09/why-are-my-lambda-functions-throwing.html