Chapter 6

Working with Delegates, Events, and Exceptions

What You Will Learn in This Chapter

  • Understanding delegates and predefined delegate types
  • Using anonymous methods including lambda expressions
  • Publishing and subscribing to events
  • Allowing derived classes to raise base class events
  • Catching, throwing, and rethrowing exceptions
  • Creating custom exceptions


You can find the code downloads for this chapter at on the Download Code tab. The code is in the chapter11 download and individually named according to the names throughout the chapter.

Chapter 3, “Working with the Type System,” explained data types including predefined types (such as int and string), data structures, and enumerations. For example, the following code snippet defines a Person structure that groups a person’s name and address information:

struct Person
    public string FirstName, LastName, Street, City, State, ZIP;

This chapter explains delegates, data types that define kinds of methods. It also explains events (which use delegates), exceptions, and error handling.

Table 6-1 introduces you to the exam objectives covered in this chapter.

Table 6-1: 70-483 Exam Objectives Covered in This Chapter

ObjectiveContent Covered
Manage program flowCreate and implement events and callbacks. This includes creating event handlers, subscribing and unsubscribing from events, using built-in delegate types to create events, creating delegates, ...

Get MCSD Certification Toolkit (Exam 70-483): Programming in C# now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.