拉姆达EX pressions和匿名方法之间的区别 - C# [英] Difference between lambda expressions and anonymous methods - C#
问题描述
复制: <一个href="http://stackoverflow.com/questions/299703/c-delegate-keyword-vs-lambda-notation">http://stackoverflow.com/questions/299703/c-delegate-keyword-vs-lambda-notation
我明白匿名方法可以用于定义委托和写内联函数。使用LAMBDA EX pressions什么不同呢?
I understand the anonymous methods can be used to define delegates and write inline functions. Is using Lambda expressions any different from this?
我想我是在什么时候使用什么糊涂一点。
I guess I am a little confused on when to use what.
修改: 此外,看来,使用匿名或lambda表达式,需要有一个扩展方法的类型?
Also, appears that to use either anonymous or lambdas, there needs to be an Extension method for the type?
推荐答案
一个拉姆达EX pression是匿名方法简单快捷方式语法。匿名方法是这样的:
A lambda expression is simply shortcut syntax for an anonymous method. Anonymous methods look like this:
delegate(params) {method body}
等价的lambda EX pression是这样的:
The equivalent lambda expression would look like this:
params => method body
在总之,所有的λ前pressions是匿名的方法,但它可能有一个未写入在lambda语法(如同第一实施例以上)匿名方法。希望这是有帮助的!
In short, all lambda expressions are anonymous methods, but it is possible to have an anonymous method that is not written in lambda syntax (like the first example above). Hope this is helpful!
这篇关于拉姆达EX pressions和匿名方法之间的区别 - C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!