O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

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

15.2. What are C# events?

Having reviewed the generic event model, I shall introduce C# events, and map C#'s implementation to the generic model.

A delegate instance encapsulates one or more (static or non-static) methods with the same return type and parameters, so that when the delegate instance is invoked all the methods in its invocation list are invoked in order with the same set of parameter values.

A C# event is a special type of delegate. It too encapsulates one or more methods – in this case, event handlers – so that when the event occurs, all these event handlers are invoked.

Event handlers usually take in two parameters, though this is not mandatory:

  • one object type which references the event source; and

  • one event object of type System.EventArgs ...

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