Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 586
MrLane Avatar asked Sep 09 '09 05:09

MrLane


1 Answers

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.

like image 167
JaredPar Avatar answered Sep 18 '22 00:09

JaredPar