2011-04-07 68 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年解決。