Member Avatar for brazentongue

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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.