Hi,
you do not have to assign a delegate an event. You create events of some
delegate type.
You declare delegates (just a special class implicitly inherited from
Delegate, or MulticastDelegate) to specify how the methods assigned to this
delegate should look like (also called a signature). They also contain a
list and some other stuff to hold the references to the methods assigned to
them, so they can fire them at some later point in time.
So you are actually subclassing Delegate or MulticastDelegate when you are
declaring a delegate (a little bit compiler magic here).
You can instantiate delegates like any other type, assign your methods to
it, fire them and so on.
Now, when you declare an event (of some delegate type), you are just
creating a delegate of that type, so it can hold references to methods (with
the same signature). It only looks different. The reason why you need to
add the 'event' keyword is to let the compiler know it is an event, so it
shows up in the property inspector (in case of a component). The compiler
also generates two hidden methods to add and remove methods to the event (or
delegate if you like). That's why you can use the += and -= syntax.
The compiler will also add a hidden delegate instance which will actually
hold the references assigned to the event. Again compiler magic.
So, an event is more or less the same as a delegate instance, with some
hidden extras to make it visible to the designer and to make it easier to
use (+= and -=).
Hope this helped a bit,
Bram.
"Michael McDowell" <mi*****@triggerwave.co.uk> wrote in message
news:Oe**************@TK2MSFTNGP09.phx.gbl...
I'm confused:
"why do we need to assign a method to a delegate then assign the delegate
to an event why not just assign the method to the events event handler"
and
"how does making a callback to some method differ from calling the method
as per normal"?
If anyone's got a minute or two to explain this stuff to me I'd be really
appreciative (even a pointer to an online paper would do).
Confused,
Michael
--
This email has been scanned with Norton AntiVirus 2003.