Delegates and Events

The next chapter pertains to delegates and events, which are related topics. Function pointers are prevalent in unmanaged programming languages and helpful in streamlining algorithms and choosing functions at run time rather than statically at compile time. As function pointers, functions can be treated as local variables, function parameters, or even return values—which adds considerable flexibility in the way they are managed and called. Because pointers are simply pointers into raw memory, function pointers are not safe. .NET offers a type-safe version of function pointers called delegates. Delegates provide the same flexibility as function pointers but in a type-safe manner.

Delegates often are used as callbacks, where ...

Get Programming Microsoft® Visual C#® 2008: The Language 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.