Target .NET 2.0 using C# 3.0

J

Joel Lyons

The C# compiler in VS 2008 doesn't complain when I use some of the new
features of C# 3.0 (list initializers, etc.)even though my assemblies are
being built for .NET 2. I'm guessing this is because they are just compiler
tricks and don't take advantage of anything new in the .NET 3.5 runtime.
Has anyone seen a document describing which additions in C# 3.0 can be used
when building a .NET 2 assembly and which can't?

Joel Lyons
 
M

Marc Gravell

Basically, you can't compile a lambda to an Expression (since the
Expression class is in System.Core), and you can't use the System.Core
LINQ-to-objects implementation (you'd need to provide your own) - but
at the /compiler/ level LNIQ works.

The rest (automatic properties, "var", lambda-to-delegate, etc) is
available. For extension methods you need to use a dirty trick, but it
can be done.

Here:
http://www.danielmoth.com/Blog/2007/05/using-c-30-from-net-20.html
and
http://www.danielmoth.com/Blog/2007/05/using-extension-methods-in-fx-20.html

Marc
 
R

Ralf Rottmann \(www.24100.net\)

Hi Joel,

There is nothing like a .NET 3.5 runtime. The .NET Common Language Runtime
has not changed sinced version 2.0! Basically this means, that on the IL
(Intermediate Language) level, "all code remains equal" ever since CLR
version 2.0.

Framework versions 3.0 and 3.5 delivered additional functionality by
_adding_ namespaces and respective assemblies. In addition the C# compiler
learned new "tricks" in the latest versions which at the end of the day
compile your code down to work on the 2.0 CLR.

Hope this helps,
Ralf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top