What is the name of this operator =>?

Possible duplicate:
What is => a token is called?

What is the name of this operator in C #?

+6
c # nomenclature
source share
4 answers

It is referred to as a lambda operator in MSDN docs .

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

+16
source share

Is the lambda operator.

As a note in Ruby, it is known as the hashrocket statement.

+3
source share

If you speak in the context of LINQ, which is the lamdba operator .

Such as the...

var selectedValues = myList.Where(v=>v.Name="Matt"); 

You can use them in your own methods instead of degats. Possible uses would include something like this ...

 void DoWork<T>(T input, Func<T, bool> doAction, Action<T> action) { if (doAction(input)) action(input); } 

... using the above method will look like ...

 DoWork(5, i=>i>1, v=>Console.WriteLine(v)); 

... because 5 is greater than 1, this displays 5 on the console.

+2
source share

FWIW, for rubists, this operator is called a "hash rocket." (There's even a company with that name .)

0
source share

All Articles