Re: The practical use of delegates

Tech-Archive recommends: Speed Up your PC by fixing your registry



Hi,

"OldCaDog" <sbass93az@xxxxxxxxxxxxxxxx> wrote in message
news:62900D3D-F598-4A8D-813F-D31820CD9804@xxxxxxxxxxxxxxxx
My question is regarding the use of delegates in C#. I see how .Net uses
delegates to wire event handlers to events. It's an object created by a
single line of code by the system and that makes perfect sense to me. I
understand that there is a lot of code underneath that the system has
created
that makes it all work, thereby making it pretty efficient for the
programmer.

Outside of the use of delegates to wire event handlers, you can create
your
own delegates to make a call to a method, which according to some, makes
delegates perfect for implementing callbacks. My question is this:

In a lot situations, I can create less code by calling that function or
method directly rather than using delegates (for static or instance
methods).

You are right, but what if you do not know the actual method you will need
to call?
A callback is an excellent example of this.

In this case you need a feature that let you dynamically select which method
to call. This feature are the delegates.


.



Relevant Pages

  • Re: The practical use of delegates
    ... the callback is a perfect example. ... but then you have to have that other class call back into the calling class ... delegates to wire event handlers to events. ... Outside of the use of delegates to wire event handlers, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: The practical use of delegates
    ... One way to consider the use of delegates is like this ... Instead of doing the Observer pattern, with an interface like IObserver, ... single line of code by the system and that makes perfect sense to me. ... Outside of the use of delegates to wire event handlers, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Been away for a few months....
    ... Anyway Mike, something I thought you might be interested to know is they ... delegates. ... anywhere in that routine or from anywhere else in the entire project. ... I was surprised with that feature as well. ...
    (microsoft.public.vb.general.discussion)
  • Re: Been away for a few months....
    ... delegates. ... anywhere in that routine or from anywhere else in the entire project. ... I was surprised with that feature as well. ... The compiler already inlines - this is in no way related to size of il. ...
    (microsoft.public.vb.general.discussion)