views:

74

answers:

1

Hi all,

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 this

DoSomething(delegate { ... });

or

DoSomething(_ => { ... });
+1  A: 

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.

Jon Skeet
Personally, I prefer not to use them, as you get clowns thinking they can be a substitute for lambda expressions, which will cause you a tonne of grief when dealing with `IQueryable`.
leppie
@jon Thanks for the answer. I too prefer the delegate syntax in this case. As you said, it makes it clear that you don't care about the parameters.
Bear Monkey