Delegates and Events (C#)

A delegate is a type that references a method. Once a delegate is assigned a method, it behaves exactly like that method. The delegate method can be used like any other method, with parameters and a return value.

Delegates have two main usages in C# programming -
1. callbacks
2. event handling
3. asynchronous method calls
5. Win32 callbacks (from Unmanaged Code)

A delegate in C# is similar to a function pointer in C or C++. It's equivalent of C/C++ callback mechanism.This feature uses Pointers to Functions to pass them as parameters to other functions.Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked

Events are the actions of the system on user manipulations (e.g. mouse clicks, key press, timer etc.) or any event triggered by the program.Events enable a class or object to notify other classes or objects when something of interest occurs. The class that sends (or raises) the event is called the publisher and the classes that receive (or handle) the event are called subscribers.


Delegates And Events - The Uncensored Story - Part 1 :

Delegates and Event Handlers -

C++ -> C#: What You Need to Know to Move from C++ to C# -