Are you asking why it's useful to derive from EventArgs
in the first place? I have to say that with C# 1 it didn't make a lot of sense, because of the way delegate conversion worked - but as of C# 2 it's more sensible. It allows an event handler to be registered with an event even if it doesn't care about the details of the event arguments.
For example:
void LogEvent(object sender, EventArgs e)
{
Console.WriteLine("Event sent from " + sender);
}
...
textArea.KeyPress += LogEvent;
This works even though Control.KeyPress
is an event of type KeyPressEventHandler
. C# and .NET don't mind that the signature of LogEvent
doesn't exactly match the signature of KeyPressEventHandler
- it's compatible enough.
Admittedly this would still be feasible if we didn't have EventArgs
at all (you could just use object
) but given the EventArgs
class and the pattern, it makes sense to derive your own event arguments from EventArgs
.