Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Lambda ( => ) [duplicate]

Tags:

c#

lambda

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

Can someone 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?

like image 775
RSTYLE Avatar asked Oct 19 '10 15:10

RSTYLE


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C full form?

Full form of C is “COMPILE”.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

What are the basics of C?

C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.


3 Answers

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.

like image 156
Robert Greiner Avatar answered Oct 19 '22 15:10

Robert Greiner


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

like image 42
QYY Avatar answered Oct 19 '22 15:10

QYY


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;}
like image 5
AlwaysAProgrammer Avatar answered Oct 19 '22 14:10

AlwaysAProgrammer