tags:

views:

306

answers:

6

I saw this

i >= 5

but I also saw this

i => 5

What's the difference?

+3  A: 

i => 5 is a lambda expression, which takes on argument named i and returns the int 5.

sepp2k
+2  A: 

i >= 5 is a comparison
i => 5 is lambda syntax

BioBuckyBall
+3  A: 

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

saurabh
+3  A: 

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.

linuxuser27
+19  A: 

=> 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.

SeeSharp
+1  A: 

=> 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".

=> Operator (C# Reference)

>= Operator (C# Reference)

Azhar