Lambda-Expressions

  • Thread starter Stefan Hoffmann
  • Start date
S

Stefan Hoffmann

hi @all,

I stumbled upon this one:

MethodInvoker listMethodInvoker =
() => list = Broker.RetrieveList<T>();

This works fine for me under VS2008 and target .Net 2.0. The question
is: Why?

All sources in the net state that lambda expressions where introduced
with C# 3.0.

(VS2008 == C# 3.0) ?


mfG
--> stefan <--
 
M

Marc Gravell

VS2008 uses C# 3 even when targetting .NET 3.0 or .NET 2.0; the
language and the runtime are separate things. Equally, you can use
anonymous types, auto-implemented properties, etc with .NET 2.0 and
VS2008. You can even use extension methods if you declare a missing
attribute - or LINQ-to-Objects is fairly easy to reproduce (see:
LINQBridge).

Marc
 
M

Marc Gravell

One other clarification: lambda expressions can be compiled either to
a delegate or to an Expression. The delegate form (which you are
using) can be used with .NET 2.0 etc, as it is the same as an
anonymous method. The Expression form uses types that are only
available in .NET 3.5 (and would be painful to back-port to .NET 2.0,
so I don't anticipate a LINQBridge equivalent for Expression).
Finally, there is also a "lambda statament" - this is always compiled
to a delegate instance, so can be used with .NET 2.0 etc.

Marc
 
P

Pavel Minaev

Stefan Hoffmann said:
hi @all,

I stumbled upon this one:

MethodInvoker listMethodInvoker =
() => list = Broker.RetrieveList<T>();

This works fine for me under VS2008 and target .Net 2.0. The question is:
Why?

All sources in the net state that lambda expressions where introduced with
C# 3.0.

(VS2008 == C# 3.0) ?

VS2008 always compiles C# as 3.0, even if you target .NET 2.0. "Target
framework" only defines the set of assemblies your program will depend on,
not the language features. So you can use all the new C# 3.0 language
features, and still run on .NET 2.0. Some of the new features - such as
LINQ - require some library stuff, but so long as you have it for 2.0, you
can use them there too. For example, to use LINQ on 2.0, try LINQBridge.
 
H

Hans Kesting

Stefan Hoffmann expressed precisely :
hi @all,

I stumbled upon this one:

MethodInvoker listMethodInvoker =
() => list = Broker.RetrieveList<T>();

This works fine for me under VS2008 and target .Net 2.0. The question is:
Why?

All sources in the net state that lambda expressions where introduced with C#
3.0.

(VS2008 == C# 3.0) ?


mfG
--> stefan <--


VS2008 does indeed always work with the C# 3.0 compiler and you can
choose the *framework* version to compile against (2.0, 3.0, 3.5).
To make it even more complicated, everything uses CLR version 2.

Hans Kesting
 
S

Stefan Hoffmann

hi Marc,

Marc said:
VS2008 uses C# 3 even when targetting .NET 3.0 or .NET 2.0; the
language and the runtime are separate things. Equally, you can use
anonymous types, auto-implemented properties, etc with .NET 2.0 and
VS2008.
Thanks, that was my finding, too. But I wasn't aware of it.



mfG
--> stefan <--
 

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