I've been reading some free web tutorials covering delegates and events in C#, but I am still confused about how delegates & event handlers tie in. Please tell me if I am understanding this correctly:

An event is triggered, which calls a delegate, which refers to an event handler method (which is the method that carries out whatever task needs to be done when the event is triggered).

Is that the correct order of execution? Also, what are some reasons to use delegates rather than calling a method directly?

6 Years
Discussion Span
Last Post by nick.crane

Your description seems correct to me.

The only thing I would like to add is that most events are managed using a MulticastDelegate. This is basically a collection of Delegates that are all called when the event is fired.

A good way to describe a Delegate is as a "type safe" function pointer.
Therefore delegates can be used (almost) anywhere you would use a function pointer.
This would mostly be when you only have access to the actual method at runtime and not during compilation (as with events).
Or if you wish to be able call methods of different classes without being tied to class types or interfaces.

This thread shows a use of delegates for something other than events.
It might help.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.