Three related idioms: event, delegate, event-handler. I always get confused by who is “added” to who.
event += handler
event += delegate
handler += delegate
From what I know:
- delegate: a pointer to a function with a known signature.
- event-handler: a delegate which is registered to an event. Basically, is it the same as a delegate?
- event: a list of delegates\event-handlers which are executed when the event is invoked using event()
What confuses me more is this signature in MSDN:
public delegate void EventHandler(Object sender, EventArgs e)
Here is my summary (please correct me if I’m wrong):
delegateis a pointer to a method (instance\static)eventHandleris a delegate with a specific signature (sender, eventArgs)eventis an abstraction of accessing a delegate of any type, but it’s usually aneventHandlerby conventionI want to recommend the great article Event Handling in .NET Using C#.
So we can only attach (eventName):
Which is equivalent to (_eventName is a delegate\eventHandler):