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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top