When use a delegate?

When use a delegate?

am 11.04.2008 00:54:19 von Cirene

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

Re: When use a delegate?

am 11.04.2008 01:11:05 von NoSpamMgbworld

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!
|
*************************************************
"Cirene" wrote in message
news:eeT9P31mIHA.4208@TK2MSFTNGP02.phx.gbl...
> When would you choose to use a delegate rather than calling a function
> directly? What's the advantages? Thanks...
>

Re: When use a delegate?

am 11.04.2008 01:22:18 von smar

Sometimes you don't know what function you're going to want to call, only
its signature. Delegates allow you that flexibility.


"Cirene" wrote in message
news:eeT9P31mIHA.4208@TK2MSFTNGP02.phx.gbl...
> When would you choose to use a delegate rather than calling a function
> directly? What's the advantages? Thanks...
>

Re: When use a delegate?

am 11.04.2008 01:33:25 von Peter Schwartz

"Cirene" wrote in message
news:eeT9P31mIHA.4208@TK2MSFTNGP02.phx.gbl...
> 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.2 WhyDelegates4

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

Re: When use a delegate?

am 11.04.2008 04:17:11 von Cirene

Thanks Cowboy, Scott, Jordan and everyone else. You guys are awesome...

"Cowboy (Gregory A. Beamer)" wrote in
message news:u95hmA2mIHA.2304@TK2MSFTNGP05.phx.gbl...
> 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! |
> *************************************************
> "Cirene" wrote in message
> news:eeT9P31mIHA.4208@TK2MSFTNGP02.phx.gbl...
>> When would you choose to use a delegate rather than calling a function
>> directly? What's the advantages? Thanks...
>>
>
>