I'm learning events in C# and understand that the EventArgs
class carries data about the event. But I am having difficulties understanding why EventArgs
is necessary.
For instance, in this MSDN example, couldn't the WakeMeUp
class read all of the necessary data (snoozePressed
, nrings
) from the fields of AlarmClock
? If it can set them, why couldn't it also get them?
The upsides with the EventArgs class are (as I see it) mainly these two:
It may even be that the information contained in the EventArgs is not exposed by the object raising the event.
Sure, in some cases it may seem like overkill, but I think that the power of sameness is a good thing here; if you know how one event works, you know how other events work as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With