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
的参数,然后使用该参数调用 Facade.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屋!
查看全文