G
Guest
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).
Are delegates good all the time, some of the time, or when? Am I missing
something? Why are so many so high on using delegates as much as they can?
Is there a security issue that makes delegates better than a direct call?
I just don’t have enough experience yet to figure this one out yet. Any
help will be appreciated. Thanks in advance for your help.
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).
Are delegates good all the time, some of the time, or when? Am I missing
something? Why are so many so high on using delegates as much as they can?
Is there a security issue that makes delegates better than a direct call?
I just don’t have enough experience yet to figure this one out yet. Any
help will be appreciated. Thanks in advance for your help.