Linq not working after .Net 2.0 to 3.5
I started developing an application several weeks ago and decided today that I may want to use LINQ. So I changed my project from .NET Framework 2.0 to 3.5 and restarted the program.
However, I can not get the most basic LINQ statement to work. I thought it was my code until I started a blank .NET 3.5 project and inserted the basic code (below) which worked without issue. So I then started another .NET 2.0 project and inserted the code (which I knew wouldn't work) and the errors are the same as the project that I converted. So next I converted this new .NET 2.0 to 3.5 and the code still doesn't work. So migrating from 2.0 to 3.5 isn't working for LINQ.
My question is: If one changes from a .NET 2.0 to a .NET 3.5 how do they get LINQ to work properly?
Thanks in advace for your suggestions. :)
Code:
' Data source.
Dim numbers() As Integer = {0, 1, 2, 3, 4, 5, 6}
' Query creation.
Dim evensQuery = From num In numbers
Where num Mod 2 = 0
Select num
' Query execution.
For Each number In evensQuery
Console.Write(number & " ")
ListBox1.Items.Add(number)
Next
Re: Linq not working after .Net 2.0 to 3.5
Did you check your references to see if you still have a reference to the LINQ library? And did you import LINQ?
Re: Linq not working after .Net 2.0 to 3.5
Yeah. I just tested it. You have to import System.Linq.
Just for future reference, you should always look up errors either directly at MSDN or just doing a search, before coming to the forums.
I looked up this message and found an article on MSDN that you can read here.
Quote:
Queryable types are defined in the System.Linq, System.Data.Linq, and System.Xml.Linq namespaces. You must import one or more of these namespaces to perform LINQ queries.