Search code examples
c#lambdamethod-group

Difference between lambda expression and method group


What's the difference between

Class1.Method1<Guid, BECustomer>("cId", Facade.Customers.GetSingle);

and

Class1.Method1<Guid, BECustomer>("cId", x => Facade.Customers.GetSingle(x));

?

Resharper suggests to use the first expression.


Solution

  • 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.