Pergunta

Possible Duplicate:
What is the => token called?

What is the name of this operator in C#?

Foi útil?

Solução

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:

Outras dicas

Is the lambda operator.

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

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.

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top