tags:

views:

94

answers:

3

I was pleasantly surprised a few months ago to learn that I could use many C# 3.x constructs (anonymous types, lambdas, automatic properties) in C#2.0, due to the fact that they all compile to the same IL...in effect, syntactic sugar.

Is this also the case of LINQ and XLINQ? Can i use these constructs while still targeting C#2.0 runtimes?

+2  A: 

LINQ is a set of extension methods defined in the System.Core assembly which is part of .NET Framework 3.5. So in order to use LINQ and LINQ to XML you will need to have .NET Framework 3.5 installed on the target machine because your application will have a static dependency on this assembly.

There's a nice diagram showing what's included in different versions of the framework.

Darin Dimitrov
+1  A: 

yes @miguel it is syntactic sugar, but it is really helpful and tasty. The Linq came to scene with C# 3 so per se you cannot use LINQ things in 2.0 version.

TheVillageIdiot
+1  A: 

For info, much of the core of LINQ is available in .NET 2.0 (with C# 3.0) via (for example) LINQBridge. This gives you most of LINQ-to-Objects (allowing query syntax against in-memory collections/iterators), but it doesn't provide the new assemblies required for LINQ-to-XML or LINQ-to-SQL etc.

So no; you can't use XDocument without the new assemblies from .NET 3.5; but you can do many LINQ things.

Marc Gravell