MrLane
MrLane

Reputation: 1728

C#: Action delegate vs explicit delegate

Just a quick one: what are peoples thoughts on using Action delegates for public class events vs defining ones own event delegate types? I know many use Actions for "minor" delegates such as in lamdas and .ForEach() extension methods, etc, but for actual class event members, is using Actions a good idea? What is "best practice" in this area.

Thanks

Upvotes: 6

Views: 2357

Answers (1)

JaredPar
JaredPar

Reputation: 754655

Instead of Action, I use EventHandler<TEventArgs> for any event declarations. It removes the need for me to define my own delegate type. It also has the additional benefit of forcing the data type to be derived from System.EventArgs and hence plays nicely with .Net event patterns.

Upvotes: 11

Related Questions