Difference between delegate {} and (input parameters) => {}
I have a few methods like this
public void DoSomething(Action<int> action) { ... }
In some cases I do not use the parameters passed into action. Are there any differences I should be aware of between calling it like thi开发者_运维知识库s
DoSomething(delegate { ... });
or
DoSomething(_ => { ... });
No, they're equivalent. Personally I prefer delegate {}
as it's obvious that you don't care about the parameters (to the extent of not even naming them), and you don't need to adapt the code based on the delegate signature - but both are fine.
精彩评论