"Ant" <An*@discussions.microsoft.com> wrote in message
news:B0**********************************@microsof t.com...
Hello,
Very simple question but one I need clarified.
Which part of the statement below is considered the 'delegate'?
Is it the 'new System.EventHandler'
or the
btnAccept_Click?
or is it the piece of code which doesn't appear here, but abstracts the
btnAccept_Click method?
this.btnAccept.Click += new System.EventHandler(this.btnAccept_Click);
Many thanks for any answers to this semingly silly question.
The delegate is Click.
The only difference between
"public event EventHandler Click;" and "public EventHandler Click;"
is the operations that you are allowed to perform on the delegate from
outside the class.
From inside the class they are indistinguishable other than by reflection.
Just to confuse you, although declared as delegate, the actual base type of
EventHandler and all other delegates is actually System.MulticastDelegate
rather than System.Delegate.
Also remember that += is not an instance operation but actually effectively
something like:
Click = EventHandler.operator+(Click,handler);
rather than
Click.Add(handler);
This allows it to work with Click == null.
For the first handler add you have
Click = EventHandler.operator+(null,handler1); --> Click == handler1
If you add another you have effectively:
Click = EventHandler.operator+(handler1,handler2) --> Click == handler3
where handler3 calls handler1 and handler2