EventHandler and EventArgs

When designing frameworks, consistency is all important to make people feel at home with new APIs quickly. For educational purposes, we’ve approached the concept of events from their essential property: Events are nothing but delegates in disguise. In doing so, we chose simple delegate types for our examples, as follows:

image

In practice, it’s more common to follow a certain pattern for events that makes their handlers have a consistent shape. We’ve already seen such a case in passing, when showing off an event handler for a button control’s Click event in Windows Forms:

From this signature, you can infer the type of the ...

Get C# 4.0 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.