开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜