Delegates

Delegates provide a mechanism for defining and executing callbacks to the system.

 

Callback provides a convenient mechanism whereby user can extend the functionality of a component. Even the most basic component of a Win32 GUI application- the window procedure- is a callback function that is registered with the system. The system calls the function any time it needs to notify you that a message for the window has arrived.

 

When you declare a delegate, the c# compiler generates a class derived from MultiCastDelegate and the CLR implements all of the methods of delegate dynamically at runtime.

 public delegate void ProgressChanged(int value);  
public class ProgressChanged : System.MulticastDelegate
            public void Invoke(int value);              
}

Continue ReadingDelegates