Solved

Please explain this lambda expression

Posted on 2010-08-18
5
220 Views
Last Modified: 2013-12-17
 Thread t = new Thread ( () => Console.WriteLine ("Hello!") );
  t.Start();


What version of C# (or .NET Framework) is needed for this to compile?

Is this an lambda expression which uses an anonymous method?

How would you explain exactly what this is?  I am new to LINQ and multi-threading...

Thanks,
newbieweb
0
Comment
Question by:newbieweb
  • 2
  • 2
5 Comments
 
LVL 27

Accepted Solution

by:
nmarun earned 333 total points
ID: 33467513
You need .net 3.0 to compile lambda expressions. Here's a nice article about lambda expressions.http://msdn.microsoft.com/en-us/library/bb397687.aspxArun
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 167 total points
ID: 33467528
That should compile on .Net 3.0 or above. A Lambda expression is essentially an anonymous method, so in this scenario it is being used in place of a ThreadStart delegate.
0
 

Author Comment

by:newbieweb
ID: 33467553
> A Lambda expression is essentially an anonymous method

is that true for all Lambda expressions?


Also, in this code, the body {} is basically the body of the anonymous method?

new Thread (() =>
{
  Console.WriteLine ("I'm running on another thread!");
  Console.WriteLine ("This is so easy!");
}).Start();
0
 
LVL 27

Assisted Solution

by:nmarun
nmarun earned 333 total points
ID: 33467598
Yes for the first question. And yes your understanding is right.Arun
0
 

Author Closing Comment

by:newbieweb
ID: 33467690
Thanks.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question