On Tue, 24 Jun 2008 23:51:03 -0700, Tony <jo*****************@telia.com>
wrote:
Is it the normal procedure in C# and .NET framework to always use the
actual
event object which is
passed as the second parameters to the event handler.
All of them are derived from the base class which is EventArgs so
because of
this the second parameters could in all cases be EventArgs which had be
be
cased
in the most cases to the the actual referenced event argument object
before
accessing the referenced object.
Typos notwithstanding, you've answered your own question. :)
Most of the time, you want the data that's in that EventArgs sub-class.
It wouldn't make any sense to declare your event handler method to take
EventArgs instead, only to have to cast it before you use it.
So, yes...I feel it's "the normal procedure" to always use the actual
type, rather than the base type.
I suppose that for an event handler where you're going to ignore that
parameter, you could declare the argument as just the base class. In
fact, that might help document the fact that the handler method is
ignoring the parameter. But in that scenario, you might want to ask
yourself why it is you're handling the event in the first place. :)
(That's for events that actually do sub-class the EventArgs; obviously for
events that don't, you'd use EventArgs and that'd be perfectly normal).
Pete