什么是'=>'语法在C#是什么意思? [英] What does the '=>' syntax in C# mean?

查看:635
本文介绍了什么是'=>'语法在C#是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在这个语法中的一些在这个论坛的问题,但谷歌和任何其他的搜索引擎往往会屏蔽掉什么,但字母和数字的搜索,这样就不可能搜索出=>

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?

推荐答案

这是拉姆达运营商,用于拉姆达前pressions 的。这些基本上是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?

(事实上很多类似的问题 - 尝试拉姆达并的λ-EX pressions 标签。)

(And indeed many similar questions - try the lambda and lambda-expressions tags.)

这篇关于什么是'=&GT;'语法在C#是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆