The classic general C# event has these parameters:
(object sender, EventArgs e)
I can implement an event with a more specific signature for the e
argument, deriving for EventArgs
.
Now, what's the purpose of a base class like EventArgs
? I mean... it's empty. No base/abstract/virtual properties, nor fields, or something else.
Why the parameters of a basic event aren't just like below?
(object sender, object eventArgs)
That is, why all the event with some implemented and specific event-args parameter derive it from EventArgs
and not from a simple object
?
The above question is mirrored with the following one. The event delegate in the generic form is:
delegate void EventHandler<TEventArgs>(object sender, TEventArgs e)
and no restrictions are put on the parameter e
. But I would have expected something like where TEventArgs : EventArgs
, to be coherent...
object
would also work for that... except for the.Empty
thing – HypoglycemiaEventArgs
. Just inheritance consistency. – Readerobject
but it's presumed that we want to pass a reference to the source of the event. In many cases the source is irrelevant to start with. But if it's not even strongly typed and could literally be anything (sender
could be anint
) then I don't see the point. I design events the same way I design any other class - with the methods and arguments I need. – Tomsk