delegates

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

what is the advantage in using delegates over calling the method directly. I
guess we get run time binding to method calls, but what do I gain with this
flexibility.
 
Mike,

Sometimes you don't know which object to call the method on at compile time.
This is where delegates come in - since they are really classes that
encapsulate a function pointer, they provide the ability to invoke the code
you want without having a specific reference to a particular object. In
other words, you can resolve which function to invoke at runtime rather than
at compile time. This makes them especially useful in callbacks and in
events.

Ginny Caughey
Windows Embedded MVP
 
Delegates provide a way to notify a set of *mutliple* *anonymous*
subscribers. Suppose you are writing a library. In that case you will not be
able to know in advance about the data types of the objects that might
supply a callback to you. Delegates are pertty much like connection points
in COM
 
Back
Top