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. 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.




Programming Microsoft Visual C# 2005(c) The Language
Microsoft Visual Basic 2005 BASICS
ISBN: 0619267208
EAN: 2147483647
Year: 2007
Pages: 161

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net