简体   繁体   English

> =和=>之间有什么区别?

[英]What is the difference between >= and =>?

I saw this 我看到了这个

i >= 5

but I also saw this 但我也看到了这个

i => 5

What's the difference? 有什么不同?

=> on MSDN The => token is called the lambda operator. =>在MSDN上 => token被称为lambda运算符。 It is used in lambda expressions to separate the input variables on the left side from the lambda body on the right side. 它在lambda表达式中用于将左侧的输入变量与右侧的lambda体分开。 Lambda expressions are inline expressions similar to anonymous methods but more flexible; Lambda表达式是类似于匿名方法的内联表达式,但更灵活; they are used extensively in LINQ queries that are expressed in method syntax. 它们广泛用于以方法语法表示的LINQ查询中。 For more information, see Lambda Expressions (C# Programming Guide). 有关更多信息,请参阅Lambda表达式(C#编程指南)。

>= 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. > = on MSDN所有数字和枚举类型定义“大于或等于”关系运算符,> =如果第一个操作数大于或等于第二个,则返回true,否则返回false。

i => 5是一个lambda表达式,它接受名为i参数并返回int 5。

1st one is checking "is i greater than equal to 5?" 第一个是检查“我是否大于等于5?”

2nd one is the lambda expression. 第二个是lambda表达式。

read more about labda expression at 阅读更多关于labda表达式的信息

http://msdn.microsoft.com/en-us/library/bb397687.aspx http://msdn.microsoft.com/en-us/library/bb397687.aspx

The first statement is a comparison expression, i is greater than or equal to 5 . 第一个语句是比较表达式, i大于或等于5 It evaluates to true or false . 它评估为truefalse The second is a lambda expression . 第二个是lambda表达式 It defines a lambda that takes an argument and evaluates to the value of 5 . 它定义了一个lambda ,它接受一个参数并计算值为5

i >= 5 is a comparison i >= 5是比较
i => 5 is lambda syntax i => 5是lambda语法

=> is Lambda operator and is read as " goes to " =>是Lambda运算符,读作“ goes to

eg 例如

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” 在上面的例子中,表达式被读作“Min w转到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 >=是关系运算符,表示“ greater than or equal ”,如果第一个操作数大于或等于第二个,则返回true否则返回false

eg 例如

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". 所以在这个例子中它将是false并且将显示“Number小于12”。

=> Operator (C# Reference) =>运算符(C#参考)

>= Operator (C# Reference) > =运算符(C#参考)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM