开发者

Difference between delegate {} and (input parameters) => {}

开发者 https://www.devze.com 2023-01-18 09:16 出处:网络
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

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

精彩评论

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