Chapter 10. Events and Delegates

IN BRIEF

When developers made the switch from functional programming to object-oriented programming, many things became easier. The Win32 development model relies heavily on the concepts of function pointers and callbacks. In other unmanaged languages, the use of function pointers can be fraught with errors caused by type conversions. Most developers who are familiar with pointer programming are also familiar with the fact that type conversions are always a source of pain and stress.

One of the advantages of C# is how operations related to type conversion can be protected. C# doesn't support pointers to functions, but it does enable developers to use delegates and events for the implementation of callbacks and notifications. A delegate is a mechanism of the .NET Framework that is, in a nutshell, a type-safe, managed function pointer.

This chapter explains what delegates are and how to use them in C# applications. The chapter also describes the internal structure of delegates and many of the features related to building event-based systems in C#.

WHAT YOU NEED

RECOMMENDED SOFTWARE.NET Framework Visual Studio .NET
RECOMMENDED HARDWARE.NET-enabled desktop client
SKILLS REQUIREDC# coding

EVENTS AND DELEGATES AT A GLANCE

What Is a Delegate?210
 Types of Delegates215Combined Delegates219
 Delegates Inside218Events221
Summary226
Further Reading226

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.144.59