I understand the benefits of events using delegate types with signature delegate void delegate_name(object sender, EventArgs e)
a) But besides the fact that it may save us some typing, are there any other reasons why we should use already defined delegate types EventHandler/EventHandler<T> instead of declaring our own delegate types with signature delegate void delegate_name(object sender, EventArgs e)?
b) Two other reason I can think of for using the predefined delegate types EventArgs/EventArgs<T> are:
-
people consuming particular event ( say
event EventHandler my_event) will immediately know how to use that event? -
perhaps some popular third party methods accept as parameters
EventHandler/ EventHandler<T>delegate types, and thus if there’s any chance that our code may use those third party methods, we should use predefined delegatesEventHandler/Eventhandler<T>?
thank you
To me, the question is a little strange. What would be the benefit of doing this otherwise (defining delegate types that exactly match
EventHandler<TEventArgs>for someTEventArgs)?That said, there is at least one benefit I can think of to doing it the “normal” way: certain APIs already expect to deal with
EventHandler<TEventArgs>delegates; for example, Rx Extensions includes a method that looks like this:If you defined your own delegate, using methods like this — which expect
EventHandler<TEventArgs>delegates — would become more complicated than necessary for no added benefit (that I can see, anyway).