This notation =>
means lambda expression
example:
Enumerable.Range(0,100).Where(x=>x==1);
here x=> x==1
is a anonymous delegate accepting int
as a parameter and returning bool
. It is:
delegate bool SomeDelegate(int x);
and you can assign body of your delegate to:
bool Function(int x)
{
return x==1;
}
A lambda expression is an anonymous function that you can use to
create delegates or expression tree types. By using lambda
expressions, you can write local functions that can be passed as
arguments or returned as the value of function calls. Lambda
expressions are particularly helpful for writing LINQ query
expressions.
To create a lambda expression, you specify input parameters (if any)
on the left side of the lambda operator =>, and you put the expression
or statement block on the other side. For example, the lambda
expression x => x * x specifies a parameter that’s named x and returns
the value of x squared. You can assign this expression to a delegate
type, as the following example shows:
source:
Read about lambda expressions
Here is a SO question about why to use lambdas: C# Lambda expressions: Why should I use them?