O'Reilly logo

A Programmer's Guide to C# 5.0, 4th Edition by Nick Wienholt, Eric Gunnerson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 23

image

Events

Chapter 22 discussed how delegates can be used to pass a reference to a method so that it can be called in a general way. Being able to call a method in such a way is useful in graphical user interfaces, such as the one provided by the classes in System.Windows.Controls. It’s fairly easy to build such a framework by using delegates, but there are significant limitations to the delegate approach. Events remove those limitations.

A Simple Example Using Delegates

The following is a simple example using delegates:

using System;public class Button{    public delegate void ClickHandler(object sender, EventArgs e);    public ClickHandler ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required