Friday, December 26, 2008

How to Use .NET 3.5 Features and C# 3.0 Syntax in .NET 2.0?

It is possible to benefit from some of the .NET 3.5 features and new syntactic sugar in C# 3.0, while still targeting customers that have only .NET 2.0 Framework. That's because these two versions share the same .NET CLR and mainly differ in the set of libraries available and compiler being used.

Features that you can leverage, while targeting .NET 2.0 Framework:
local variable inference;
anonymous types;
object initializers;
extension methods;
query expressions (LINQ syntax);
lambda expressions;
LINQ for objects;
new C# compiler that produces better code.

I've done this for production scenarios with ASP.NET Forms and Windows.Forms and everything has been working fine. It is possible that things like WCF or Linq2DB might also be supported, but I've never given it a try.

Below you will find different options for doing this in your solutions.

Note, that in any scenario you still need Visual Studio 2008 to develop these solutions.

Referencing LinqBridge

1. Create new project targeting .NET 2.0 Framework in Visual Studio 2008. This will already give you new syntax capabilities of C# 3.0

2. Download LinqBridge

3. Reference it in the project to get support for the extension methods and LINQ extensions.

Read More...

1 comment:

Unknown said...

Thank you for sharing this post about the best techniques for osCommerce Development, This is very useful for osCommerce Development and osCommerce Development Company. Thanks again :) osCommerce Development