CTS Delegate Types
Delegates are the .NET equivalent of a type-safe C-style function pointer. The key difference is that a
.NET delegate is a
class that derives from System.MulticastDelegate, rather than a simple pointer to
a raw memory address. In C#, delegates are declared using the delegate keyword:
// This C# delegate type can "point to" any method
// returning an integer and taking two integers as input.
delegate int BinaryOp(int x, int y);
Delegates are useful when you wish to provide a way for one entity to forward a call to another
entity, and provide the foundation for the .NET event architecture. As you will see in Chapters 11
and 18, delegates have intrinsic support for multicasting (i.e., forwarding a request to multiple
recipients) and asynchronous method invocations.
Do'stlaringiz bilan baham: |