2012-11-06 46 views
3

我使用VS2008框架3.5,我期待有關LINQ首次,下面這個樣子http://msdn.microsoft.com/it-it/library/bb385204(VS.90).aspx與第一LINQ第一個問題

這些http://msdn.microsoft.com/it-it/library/bb385164(v=vs.90).aspx

創建數據源,但我無法導入/使用linq。製作consoleApplication System.Core.dll引用並導入System.Linq應該是自動對吧?!

寫入主:

Dim students = GetStudents() 
'Dim students As List(Of Student) = GetStudents() 'the same thing with this one 
Dim studentQuery = From currentStudent In students _ 
        Where currentStudent.Rank <= 10 _ 
        Select currejt 

的IDE不喜歡學生在查詢,並說:

Error 1 Expression of type 'System.Collections.Generic.IEnumerable(Of ConsoleApplication1.Module1.Student)' 
is not queryable. Make sure you are not missing an assembly reference and/or namespace 
import for the LINQ provider. ConsoleApplication1 

在那裏我錯了!?

,如果我嘗試「進口System.Linq的」它說

警告1個命名空間或進口「System.Linq的」 不包含任何公共成員,或者無法找到指定的類型。確保 名稱空間或類型已定義,並且至少包含一個公開的成員 。確保導入的元素名稱不使用任何別名。

+1

那麼*你*有一個參考System.Core? –

回答

1

參考和進口是不同的 - 你必須以引用您的項目(System.Core程序,其中System.Linq的命名空間駐留)該DLL,以便能夠將其導入到你的類...

右鍵單擊Project/References,選擇添加引用,轉到選項卡「.NET」並選擇System.Core。

+0

謝謝這就是問題...我不能添加該DLL,因爲現在項目設置在框架目標2.0上,我可以將其更改爲3.5?再次感謝 – giacomo

+0

解決! for anyonelse with same problem: VB項目 項目屬性 - >編譯 - >高級編譯選項 謝謝 – giacomo