Vb lambda max function

I have a problem using vb equivilant expressions of MAX lambda. in foos.Max (function (x) x.id) , when I try to intellisense the ID property, VS will not show it. But when I run the example, it works. Is there something that I am doing that is wrong, I was just lucky that it works?

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 
+6
source share
1 answer

You did not specify which version of Visual Studio you are using, but I think this is VS 2008, since IntelliSense works correctly in VS 2010. In addition, this was reported to Microsoft and they stated that they will be fixed in the next version of Visual Studio. which at the time of writing this report would be for 2010.

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

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

By adding As Foo , you should get IntelliSense support. To repeat, the problem was resolved in VS 2010.

+7
source

Source: https://habr.com/ru/post/885414/


All Articles