lambda表达式和方法组之间的差异 [英] Difference between lambda expression and method group
本文介绍了lambda表达式和方法组之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么
Class1.Method1<Guid, BECustomer>("cId", Facade.Customers.GetSingle);
和
Class1.Method1<Guid, BECustomer>("cId", x => Facade.Customers.GetSingle(x));
?
ReSharper的建议使用一个表达式。
Resharper suggests to use the first expression.
推荐答案
有是在问候的结果没有什么区别。然而,第二个创建一个额外的重定向:代码会先调用您的匿名方法的需要命名一个参数 X
而这又调用门面。 Customers.GetSingle
与参数。这种重定向没有任何好处可言,这就是为什么ReSharper的告诉你使用的第一个选择。
There is no difference in regards to the result. However, the second one creates an additional redirection: The code will first call your anonymous method the takes one parameter named x
and that in turn calls Facade.Customers.GetSingle
with that parameter. This redirection has no benefit at all, that's why ReSharper tells you to use the first alternative.
这篇关于lambda表达式和方法组之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文