Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Daniel Solis - Illustrated C# 2010 - 2010.pdf
Скачиваний:
20
Добавлен:
11.06.2015
Размер:
11.23 Mб
Скачать

CHAPTER 16 EVENTS

Overview of Source Code Components

Five components of code need to be in place to use events. I’ll cover each of them in the following sections, and they are illustrated in Figure 16-4. These components are the following:

Delegate type declaration: The event and the event handlers must have a common signature and return type, which is described by the delegate type declaration.

Event handler declarations: These are the declarations in the subscriber classes of the methods (event handlers) to be executed when the event is raised. These do not have to be separate methods. They can be anonymous methods or lambda expressions.

Event declaration: This is the declaration in the publisher class of the event that holds and invokes the event handlers.

Event registration: This is the code that connects the event handlers to the event.

Code that raises the event: This is the code in the publisher that calls the event, causing it to invoke its event handlers.

Figure 16-4. The five source code components of using an event

394

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]