没有智能感知的 VB.Net Lambda 表达式
在 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
Using lambda's in VB.Net results in no intellisense. Is this a bug with VS2010 or expected? Note that it works fine in 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
UPDATE: Here's an example
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对象数组不像 List(Of T) 类那样是强类型的。所以当你输入“x”时。并期望“Number”出现在 Intellisese 中,但它不会。运行时不知道该数组中的对象类型。
如果您选择这样做,则可以使用 LINQ 将该数组转换为强类型对象集合,然后会向您显示 Intellisense。以下行应该正常工作:
Dim ChequeList = (From c In MyArrayOfObjects Select c).ToList()
另外还有一件事要检查 VB.NET 与 C# 智能感知。 “选项推断”必须打开。默认情况下是这样,但不适用于已升级的项目(即从 05 -> 08 -> 10 升级)
为什么我的 Lambda 函数在运行时抛出 System.MissingMemberException 错误例外?
http://allen-conway -dotnet.blogspot.com/2010/09/why-are-my-lambda-functions- throwing.html
An array of object is not strongly typed like a List(Of T) class would be. So when you type 'x.' and expect 'Number' to show up in Intellisese, it will not. The runtime has no idea of the object types within that Array.
If you chose to do so, you could use LINQ to convert that Array into a stongly tped object collection, that would then show you the Intellisense. The follwing line should work properly:
Dim ChequeList = (From c In MyArrayOfObjects Select c).ToList()
Also one other thing to check for the VB.NET vs C# intellisense. 'Option Infer' must be turned 'On'. It is by default, but not for upgraded projects (i.e. upgraded from 05 -> 08 -> 10)
Why Are My Lambda Functions Throwing An Error at Run Time With a System.MissingMemberException Exception?
http://allen-conway-dotnet.blogspot.com/2010/09/why-are-my-lambda-functions-throwing.html