问题描述
我刚刚在这个语法中的一些在这个论坛的问题,但谷歌和任何其他的搜索引擎往往会屏蔽掉什么,但字母和数字的搜索,这样就不可能搜索出=>
I just came over this syntax in some of the questions in this forum, but Google and any other searchengine tends to block out anything but letters and number in the search so it is impossible to search out "=>".
因此,谁能告诉我它是什么以及如何使用它?
So can anyone tell me what it is and how it is used?
推荐答案
这是拉姆达运营商,用于的。这些基本上是href=\"http://msdn.microsoft.com/en-us/library/0yw3tz5k.aspx\">匿名方法的在C#2中引入的前pression树木的。
It's the lambda operator, used for lambda expressions. These are basically a shorter form of the anonymous methods introduced in C# 2, but can also be converted into expression trees.
作为一个例子:
Func<Person, string> nameProjection = p => p.Name;
相当于:
Func<Person, string> nameProjection = delegate (Person p) { return p.Name; };
在这两种情况下,你要创建一个人
参数的委托,返回此人的姓名(字符串)。
In both cases you're creating a delegate with a Person
parameter, returning that person's name (as a string).
另请参阅:
- 之间的区别
- What's the difference between anonymous methods (C# 2.0) and lambda expressions (C# 3.0)
- What is a Lambda?
- C# Lambda expression, why should I use this?
(事实上很多类似的问题 - 尝试并的标签。)
(And indeed many similar questions - try the lambda and lambda-expressions tags.)
这篇关于什么是'=&GT;'语法在C#是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!