EventHandler<T>

image Requiring (or strongly advising, for the sake of consistency) developers to create their own EventArgs derived type is enough of a burden for them, but in the early days of .NET even that wasn’t enough. One had to create a custom EventHandler delegate with the typical object sender and MyEventArgs e signature.

Since the advent of .NET 2.0, with the introduction of generics, this was simplified a bit through the introduction of EventHandler<T>:

image

The generic constraint put on the TEventArgs type argument enforces the correct use of ...

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.