Delegate

  • Thread starter Thread starter Jimmy
  • Start date Start date
J

Jimmy

Hi

Can someone tell me what the advantage of a delegate is? Maybe an example
code would help

Thanks


Jim
 
Hi,

A delegate allow you to call a different method each time, or choose at
runtime what method to call, as long as a method has the same signature that
the delegate you can use it.


Cheers,
 
Ignacio

ok but why would you use this? what is the advantage of a delegate? when
would you use it?

Jimmy
 
Jimmy said:
ok but why would you use this? what is the advantage of a delegate? when
would you use it?

For event handlers, or whenever you want a function pointer, basically.

You could think of it as a "one method interface" if you want, but you
don't need to explicitly implement it, or you can pseudo-implement it
several times in the same class (just by giving several different
methods the same signature as the delegate). You can also build
delegate instances from static methods.
 
Back
Top