When use a delegate?

  • Thread starter Thread starter Cirene
  • Start date Start date
C

Cirene

When would you choose to use a delegate rather than calling a function
directly? What's the advantages? Thanks...
 
One prime example is events.

Another is when you have to run more than one "function" when a specific
action happens.

Another is when you have a library that has to make a callback to the
calling application, but you do not know what the event name is at the time
you create the library.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************
 
Sometimes you don't know what function you're going to want to call, only
its signature. Delegates allow you that flexibility.
 
Cirene said:
When would you choose to use a delegate rather than calling a function
directly? What's the advantages? Thanks...


Here is a link to a good article that presents an introduction to
delegates - to the extent that delegates are relevant to events.

http://www.codeproject.com/KB/cs/event_fundamentals.aspx#3.2WhyDelegates4

While the article is about events, one must have a good understanding of
delegates in order to really understand events in C#. So much of the article
addresses delegates.

-HTH
 
Back
Top