Did you know that if you are using Visual Studio 2008 but targeting the .Net 2.0 framework you can still use some of the new syntax features of .Net 3.5 in your applications? That's right, you read that correctly you too can be a cool kid while still working on your old dilapidated, buggy legacy application (ok, maybe using the new syntax will not make you a cool kid... I tried).
Anyway, turns out you can use the new syntax features just as long as you do not reference the new .Net 3.5 assemblies.
The new assemblies are:
System.Data.Linq
System.Xml.Linq
System.Core
New Syntax/Features you can use is:
Var keyword
Lambda statements
Extension Methods (kinda, sort, you need to read this for more information)
Object Initializers
Anonymous Types (Moved from the cannot use section, thanks Jon)
New Syntax/Features you cannot use is:
Linq (any variant of Linq)
Query Extensions
Extension Methods (see the link above for more information)
Now you may be asking, how can you use the new .Net 3.5 stuff when targeting the .Net 2.0 framework? Well, simple all the allowed new stuff is really nothing more than compiler tricks. The 'Var' keyword really is just replaced at compile time with the strongly typed equivalent. Lambda's are really nothing more then a fancy new facade on anonymous delegates. And Object Initializers are just ways to reduce the number of lines you right.
So, if you are like me and stuck in a .Net 2.0 project but would like to use some of the new features and you are using VS 2008, have at it. Just make double sure that you are 1) targeting the .net 2.0 framework 2) you do no reference any of the new assemblies that are part of .Net 3.5.
Till next time,
[----- Remember to check out DimeCasts.Net -----]
Posted
06-16-2008 5:57 AM
by
Derik Whittaker