开发者

VB.Net Lambda expression with no intellisense

开发者 https://www.devze.com 2023-02-15 23:19 出处:网络
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#

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消