O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

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

EventHandler<T>

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 sender plus event arguments signature:

public delegate void TickEventHandler(object sender, TickEventArgs e)

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

public delegate void EventHandler<TEventArgs>(object sender, TEventArgs e)    where TEventArgs : EventArgs

The generic constraint on the TEventArgs type argument has been removed in .NET Framework ...

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