hi all
My friend says “in c#, every event handler is bound to a method which its name is On….”
I mean, for example, SelectedIndexChanged of a combobox is bound to a method named OnSelectedIndexChanged.
My question is: How can I see it?
Please tell me more about that if its possible.
Thank you
The methods that start with “On….” are used as a convention. These methods are not “bound” in any way with an event nor an event is “bound” to them (taking into consideration the generally accepted definition/procedure of registering for an event).
What they actually do is raise the event suggested by the words following the “On” prefix.
For instance:
where SelectedIndexChanged event is defined somewhere like this:
The convention and .net practices state that for each event you should have a overridable protected method that raises the event.
In a derived class you could do something like that:
NOTE: To be absolutely correct, this event and others may use different derived types from the
EventArgsclass but the concept is the same.