events Make Working with delegates Easier

Particularly for UI code, events are the primary means of notification. Button clicks, mouse over, list expansion, and so on all use events to notify the application of the occurrence of an event. events are based on delegates, so many of the same principles apply to events that apply to delegates. Events are so similar to delegates that the benefits of events are not readily apparent. Maybe a couple of examples will help you appreciate an event.

Beginning events

The first sample shows how an event can be used to notify an application that something has changed. For this sample, the change is incrementing and decrementing an integer. After each modification, the registered events are called. A portion ...

Get .NET Common Language Runtime Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.