C# – Use LINQ on .net framework 2.0

When I read a thread on mycsharp.de, I discovered a library which allow us to use LINQ in any application written on .Net Framework 2.0. It’s really great if we have this feature without installing mega framework 3.0. The library can be downloaded from google code http://code.google.com/p/linqbridge/downloads/list . You can download online .cs file or a .dll file as you link but I prefer using a .cs because I don’t have to merge .dll file to exe file after compilation. But how can LINQ work without .Net Framework 3.0. Does it depend on .Net Framework 3.0? The answer is NO. Let’s examine an example of LINQ with C# 3.0

string[] arrNames = { "ActionScript", "Batch", "CPlusPlus",
					"Delphi", "ECMAScript", "Fortran",
					"HyperTalk", "IronPython" };

IEnumerable<string> query = from s in arrNames
							where s.Length == 5
							orderby s
							select s.ToUpper();

foreach (string item in query)
	Console.WriteLine(item);
Console.ReadLine();

When compiling this code, C# 3.0 will firstly translate the keyword where, orderby, select into function Where, Orderby, Select.

string[] arrNames = { "ActionScript", "Batch", "CPlusPlus",
					"Delphi", "ECMAScript", "Fortran",
					"HyperTalk", "IronPython" };

IEnumerable<string> query = from s in arrNames
							.Where s.Length == 5
							.Orderby s
							.Select s.ToUpper();

foreach (string item in query)
	Console.WriteLine(item);
Console.ReadLine();

The compiler then looks for Where, OrderBy and Select methods. The critical thing is that it can find appropriately named methods with the correct signatures (typically extension methods). But it doesn’t matter what assembly the methods come from. That means we can use LINQBridge which simply provides another source of these methods—that are functionally identically to those implemented in the Framework 3.0.
To use this library, download .cs at the link above, add it to your project and add a using instruction “using System.Linq” then you can use LINQ in your .net 2.0 framework application. However it requires that you must have IDE Visual Studio 2008 so that the compiler version 3.0 can compile all query operators. Happy Coding.

2 thoughts on “C# – Use LINQ on .net framework 2.0”

  1. C# – Use LINQ on .net framework 2.0:

    I would like to download the .NET 2 version of System.LinQ. I do not see where the download link is. You say it is above, but above is only some adds. Could you send me the download link please?

    Thank you

    E de Villiers

Leave a Reply

Your email address will not be published. Required fields are marked *