The delegate keyword is used as part of a delegate declaration to define a class that extends com.ms.lang.Delegate, or com.ms.lang.MulticastDelegate. Delegates are commonly used within the Microsoft Windows Foundation Classes (WFC) library to build event-handling mechanisms.
Delegates roughly equate to function pointers, commonly used in C++ and other object-oriented languages. Unlike function pointers however, delegates are object-oriented, type-safe, and secure. In addition, where a function pointer contains only a reference to a particular function, a delegate consists of a reference to an object, and references to one or more methods within the object.
Either “regular” or multicast delegates may be declared, depending on the presence or absence of the multicast keyword. A “regular” delegate encapsulates a reference to a single method within an instance. When this type of delegate is invoked, the underlying method is called.
A multicast delegate differs from a regular delegate in that it may contain references to more than just one method. Methods in a multicast delegate are executed synchronously when the delegate is invoked, and in the order which they appear. If one of the called methods raises an exception, then the delegate ceases, and the exception is propagated to the delegate caller.
Note The delegate keyword is an extension to the Java language, provided by Microsoft.