Information Technology Reference
In-Depth Information
What Is a Delegate?
A
delegate
can be thought of as an object that contains an ordered list of methods with the same
signature and return type.
•
The list of methods is called the
invocation list
.
When a delegate is invoked, it calls each method in its invocation list.
Figure 15-1 represents a delegate with four methods in its invocation list.
Figure 15-1.
A delegate as a list of methods
A delegate with a single method is similar to a function pointer in C++. Unlike function
pointers, however, delegates are object oriented and type-safe.
Methods in the Invocation List
Methods held by a delegate
can be from any class or struct
, as long as they match
both
the
delegate's
Return type
Signature
Methods in the invocation list can be either instance methods or static methods.