Team LiB
Previous Section Next Section

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 REQUIRED

C# coding


EVENTS AND DELEGATES AT A GLANCE

What Is a Delegate?

210

 

Types of Delegates

215

Combined Delegates

219

 

Delegates Inside

218

Events

221

Summary

226

Further Reading

226


    Team LiB
    Previous Section Next Section