没有智能感知的 VB.Net Lambda 表达式

发布于 2024-10-20 22:34:17 字数 788 浏览 2 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倒数 2024-10-27 22:34:17

对象数组不像 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文