Reputation: 12295
I saw this
i >= 5
but I also saw this
i => 5
What's the difference?
Upvotes: 7
Views: 513
Reputation: 20680
=>
is Lambda operator and is read as "goes to
"
e.g.
string[] ldata = { "Toyota", "Nissan", "Honda" };
int shortestWordLength = ldata.Min(w => w.Length);
Console.WriteLine(shortestWordLength);
in the above example the expression is read as “Min w goes to w dot Length”
While >=
is relational operator which means "greater than or equal
" and its returns true
if the first operand is greater than or equal to the second, false
otherwise
e.g.
int lNum =10;
if(lNum >= 12)
Console.WriteLine("Number is greater than or equal 12");
else
Console.WriteLine("Number is less than 12");
so in this example it will be false
and will show "Number is less than 12".
Upvotes: 2
Reputation: 1750
=> on MSDN The => token is called the lambda operator. It is used in lambda expressions to separate the input variables on the left side from the lambda body on the right side. Lambda expressions are inline expressions similar to anonymous methods but more flexible; they are used extensively in LINQ queries that are expressed in method syntax. For more information, see Lambda Expressions (C# Programming Guide).
>= on MSDN All numeric and enumeration types define a "greater than or equal" relational operator, >= that returns true if the first operand is greater than or equal to the second, false otherwise.
Upvotes: 20
Reputation: 7353
The first statement is a comparison expression, i
is greater than or equal to 5
. It evaluates to true
or false
. The second is a lambda
expression. It defines a lambda
that takes an argument and evaluates to the value of 5
.
Upvotes: 5
Reputation: 17556
1st one is checking "is i greater than equal to 5?"
2nd one is the lambda expression.
read more about labda expression at
http://msdn.microsoft.com/en-us/library/bb397687.aspx
Upvotes: 4
Reputation: 370202
i => 5
is a lambda expression, which takes on argument named i
and returns the int
5.
Upvotes: 5