开发者

What is the difference between >= and =>?

开发者 https://www.devze.com 2023-01-16 14:21 出处:网络
I sa开发者_开发百科w this i >= 5 but I also saw this i => 5 What\'s the difference?=> on MSDN

I sa开发者_开发百科w this

i >= 5

but I also saw this

i => 5

What's the difference?


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


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


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.


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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号