Handling Events with Delegates

Objects in C# can also support events. Events were created for graphical user interfaces (GUIs) like Windows so the user can direct program execution. When something happens in a GUI—the user clicks a button, moves a scroll bar, or closes a window—an event occurs. GUI code is written to respond to events, rather than simply to execute huge monolithic code blocks without user interaction. When code responds to events, the user directs the action and the program responds.

We're going to work with events in detail when creating Windows and Web applications, because events are designed for GUI environments. However, because you can handle events in C# with delegates, we'll get an introduction to the topic here. In C#, ...

Get Microsoft® Visual C#® .NET 2003 Kick Start 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.