Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vb lambda MAX function

Tags:

vb.net

lambda

I am having an issue using the vb equivilant of the MAX lambda expression. at foos.Max(function(x) x.id) when I try to intellisense the property ID VS will not show it. But when i run the example it works. Is there something I am doing which is wrong, an i am just lucky it runs?

 Sub Main()
        Dim foos As New List(Of Foo)
        Dim bob As New Foo() With {.id = 5, .name = "bob"}
        foos.Add(bob)
        foos.Max(Function(x) x.id)
    End Sub

    Public Class Foo
        Public Property id() As Integer
            Get
                Return m_id
            End Get
            Set(ByVal value As Integer)
                m_id = Value
            End Set
        End Property
        Private m_id As Integer
        Public Property name() As String
            Get
                Return m_name
            End Get
            Set(ByVal value As String)
                m_name = Value
            End Set
        End Property
        Private m_name As String
    End Class
like image 438
gh9 Avatar asked Apr 07 '11 13:04

gh9


1 Answers

You didn't specify which version of Visual Studio you're using, but my guess is it's VS 2008 since the IntelliSense works correctly in VS 2010. Furthermore, this has been reported to Microsoft and they stated that it would be fixed in the next version of Visual Studio, which would be 2010 at the time of that report.

Your code works fine and compiles because it is correct, so you're not doing anything wrong. If you really want to get IntelliSense in VS 2008 for a lambda expression you would need to specify the type:

foos.Max(Function(x As Foo) x.id)

By adding the As Foo you should get IntelliSense support. To reiterate, the issue has been resolved in VS 2010.

like image 85
Ahmad Mageed Avatar answered Oct 12 '22 21:10

Ahmad Mageed