views:

213

answers:

4

Possible Duplicate:
What is the => token called?

What is the name of this operator in C#?

+15  A: 

It's referred to as the lambda operator in the MSDN docs.

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:

Brian R. Bondy
+2  A: 

If you are talking in the context of LINQ that is a lamdba operator.

Such as ...

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

You can use these in your own methods in place of delgates. Possible uses would include something like this...

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

... usage of the above method would look like ...

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

... because 5 is greater than 1 this would display 5 on the console.

Matthew Whited
Lambda operators aren't only used with LINQ.
Femaref
I do beleive my example shows that... I said in the context of becasue he could have seen something nuts in an example like `for (; i=>1;)` and may not realize that is a normal expression. The even more fun thing is in LINQ you could also do `.Select(i=>"New Value")` to create an enumerable set of "New Value" the length of the input set.
Matthew Whited
Just to be clear, `=>` isn't "the lambda expression" - it is *part* of it.
Marc Gravell
I assumed that was clear... but I will change my answer.
Matthew Whited
+2  A: 

Is the lambda operator.

As a side note, in Ruby is known as the 'hashrocket' operator.

Chubas
A: 

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

ewall