2011-04-07 89 views
6

我在使用MAX lambda表达式的vb equivilant时遇到了问题。在foos.Max(函数(X)x.id)当我尝试智能感知属性ID VS不会表现出来。但是,当我运行该示例它的作品。我在做什么是错的,我只是幸运而已?vb lambda MAX函数

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 

回答

7

您没有指定您正在使用的Visual Studio的版本,但我的猜测是,这是2008年以来VS智能感知正常工作在2010年VS此外,这一直是reported to Microsoft,他们表示会在Visual Studio的下一个版本中得到修复,该版本将在该报告发布时为2010年。

你的代码工作正常,并编译,因为它是正确的,所以你没有做任何错误。如果你真的想要得到的IntelliSense在VS 2008中的lambda表达式,你需要指定类型:

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

通过添加As Foo你应该得到的IntelliSense支持。重申一遍,这个问题已在2010年解决。