tags:

views:

175

answers:

5
+1  Q: 

C# Lambda ( => )

Possible Duplicates:
Good tutorials for lambda
Lamda Explanation and what it is as well as a good example
C# Lambda expression, why should I use this?

Hi can you all explain to me how to use this and give me examples. How do we read it.

Example != is read as "not equals to." So => means what?

+2  A: 

http://msdn.microsoft.com/en-us/library/bb397687.aspx

The => operator has the same precedence as assignment (=) and is right-associative.

kyndigs
That's the perfect answer. And to make it more perfect, I would add "'=>' reads 'goes to'". :)
Wonko the Sane
+1  A: 

All lambda expressions use the lambda operator =>, which is read as "goes to". The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. The lambda expression x => x * x is read "x goes to x times x." This expression can be assigned to a delegate type as follows:

From the docs

the => operator has the same precedence as assignment (=) and is right-associative.

Robert Greiner
A: 

"=>" is lambda operator and is read as "goes to"

QYY
A: 

from MSDN

A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types. All lambda expressions use the lambda operator =>, which is read as "goes to". The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. The lambda expression x => x * x is read "x goes to x times x."

saurabh
A: 

This is the lambda operator. Which means 'goes to'. It is used to create lambda expressions which is syntax offered by C# for anonymous methods.

eg. lamda expression x=>x > 2. This mean that given x, x goes to x greater than 2. In other words this lambda expression will select x greater than 2.

Anonymous method for the same can be written as

delegate(int x){return x > 2;}
Yogendra
Surely its only right to say it will select x greater than 2 if the lambda is used as part of a select. Woudln't it be more accurate to say that it would return true if x > 2 and false otherwise or something similar?
Chris
you are right. I jumbled up both of them. Good Catch
Yogendra