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. As function pointers, functions can be treated as local variables, function parameters, or even function returns—which adds considerable flexibility in the way functions are managed and called. Because pointers are simply pointers into raw memory, function pointers can be unsafe. .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 are frequently used as callbacks, in which a function is called upon something happening. The Event model promotes an effective paradigm for callbacks, where there are publishers and subscribers. Publishers expose something that happens—better known as an event. Subscribers subscribe to an event with a delegate. The delegates of the subscriber are called when the event occurs.