什么是匿名方法(C#2.0)和lambda前pressions(C#3.0)有什么区别?

问题描述:

是什么匿名方法之间的差异的C#2.0和拉姆达前pressions 的C# 3.0。?

What is the difference between anonymous methods of C# 2.0 and lambda expressions of C# 3.0.?

匿名方法的MSDN页解释它

在C#的2.0版本之前,唯一的
  方法来声明一个委托是使用
  命名方法。 C#2.0中引入
  在C#匿名方法和3.0
  后来,拉姆达前pressions取代
  匿名方法为preferred方式
  写内嵌code。然而,
  关于匿名方法的信息
  这个话题也适用于拉姆达
  前pressions。有在一种情况下
  该匿名方法提供
  在功能拉姆达未找到
  前pressions。匿名方法使
  你省略参数列表,并
  这意味着匿名方法
  可转换为代表用
  各种签名。这不是
  可能的拉姆达前pressions。对于
  特别是有关的更多信息
  拉姆达前pressions,请参见Lambda
  防爆pressions(C#编程指南)。

In versions of C# before 2.0, the only way to declare a delegate was to use named methods. C# 2.0 introduced anonymous methods and in C# 3.0 and later, lambda expressions supersede anonymous methods as the preferred way to write inline code. However, the information about anonymous methods in this topic also applies to lambda expressions. There is one case in which an anonymous method provides functionality not found in lambda expressions. Anonymous methods enable you to omit the parameter list, and this means that an anonymous method can be converted to delegates with a variety of signatures. This is not possible with lambda expressions. For more information specifically about lambda expressions, see Lambda Expressions (C# Programming Guide).

而关于拉姆达前pressions

一个拉姆达前pression是可以包含前pressions和语句,可用于创建委托或前pression树种匿名函数。
  所有的lambda前pressions使用的lambda运算符=>,它读作去。在lambda运算符的左侧指定的输入参数(如果有的话),右侧持有的前pression或语句块。拉姆达前pression X => X * X读×去x次的X.这当然pression可以分配给委托类型如下:

A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types. All lambda expressions use the lambda operator =>, which is read as "goes to". The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. The lambda expression x => x * x is read "x goes to x times x." This expression can be assigned to a delegate type as follows: