471,310 Members | 1,211 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,310 software developers and data experts.

Lambda-Expressions

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 <--
Sep 2 '08 #1
6 2214
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
Sep 2 '08 #2
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
Sep 2 '08 #3

"Stefan Hoffmann" <st*************@explido.dewrote in message
news:eJ**************@TK2MSFTNGP06.phx.gbl...
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.
Sep 2 '08 #4
hi Marc,

Marc Gravell wrote:
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 <--
Sep 2 '08 #5
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
Sep 2 '08 #6
On Sep 2, 2:43*pm, Stefan Hoffmann <stefan.hoffm...@explido.dewrote:
Marc Gravell wrote:
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.
See http://csharpindepth.com/Articles/Ch.../Versions.aspx for more
on this.

Jon
Sep 2 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

53 posts views Thread by Oliver Fromme | last post: by
63 posts views Thread by Stephen Thorne | last post: by
7 posts views Thread by Paddy McCarthy | last post: by
17 posts views Thread by mehmetmutigozel | last post: by
4 posts views Thread by Xah Lee | last post: by
8 posts views Thread by rubbishemail | last post: by
21 posts views Thread by globalrev | last post: by
1 post views Thread by Tim H | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.