在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
最佳答案
对象数组的类型不像List(Of T)类那样强。因此,当您输入“ x”时。并期望“数字”以Intellisese显示,但不会。运行时不知道该Array中的对象类型。
如果选择这样做,则可以使用LINQ将Array转换为tped对象集合,然后向您显示Intellisense。跟随线应正常工作:
Dim ChequeList =(从c在MyArrayOfObjects中选择c).ToList()
检查VB.NET与C#intellisense的另一件事。 “选项推断”必须打开。它是默认设置,但不适用于升级项目(即从05-> 08-> 10升级)
为什么我的Lambda函数在运行时因System.MissingMemberException异常而引发错误?
http://allen-conway-dotnet.blogspot.com/2010/09/why-are-my-lambda-functions-throwing.html
关于.net - 没有智能感知的VB.Net Lambda表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5247492/