Creating and Using Delegates

Delegates are the .NET equivalent of callbacks and function pointers. They are used primarily to route events to handlers as they arrive.

A delegate declaration describes a function signature with a specific pattern of parameters and a specific return type. Once this pattern is established, it might be used to invoke any function with the same signature. A difference between delegates and callbacks implemented by C++ classes is that, although callbacks in C++ must always be static members of the class, delegates can be used to invoke instance members, too.

A delegate is declared like this:

__delegate <return type> MyMCDelegate(<parameter list>);

NOTE

Delegates can have many parameters. The delegate matching pattern ...

Get C# and the .NET Framework: The C++ Perspective now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.