A delegate is a programmer-defined type that abstracts the ability to call a method. A delegate-type declaration includes the declaration of the signature and return type that the delegate encapsulates. Instances of the delegate type can then wrap any method that exposes the same signature and return type, regardless of the class on which the method is defined and whether the method is an instance method or shared method of the defining class. The method thus wrapped can be invoked through the delegate object. The delegate mechanism provides polymorphism for methods having the same signature and return type.
Delegates are often used to implement callback mechanisms. Imagine a class that will be used by a program you are writing. This class provides some useful functionality, including the ability to call in to a method that you must implement within your program. Perhaps this callback mechanism is provided to feed your program data as it becomes available in the class you are using. One way to achieve this capability is through the use of delegates. Here’s how:
The writer of the class you’re using (call it a server class) declares a public delegate type that defines the signature and return value of the method that you will implement.
The writer of the server class exposes a method for clients of the class to pass in an instance of the delegate type.
You implement a method having the appropriate signature and return value.
You instantiate a new object of the delegate ...