6

What is the difference between

public delegate void SecondChangedHandler(Object clock, TimeInfoEventArgs ti);
public event SecondChangedHandler OnSecondChanged;

and

public event EventHandler<TimeInfoEventArgs> OnSecondChanged;

When should you use which and is there any best practice?

yannis
  • 39,547
  • 40
  • 183
  • 216
user47646
  • 63
  • 2

2 Answers2

9

Before generics the first approach was the only option to declare an event handler delegate. Since generics were introduced in .NET 2.0, EventHandler<T:EventArgs> is the preferred way. Semantically there is no difference between them.

MattDavey
  • 7,096
  • 3
  • 31
  • 32
3

There is no difference indeed. Then EventHandler<T> (msdn) has just been added as a "shortcut" to avoid having to redeclare the delegate.

SRKX
  • 1,939
  • 1
  • 15
  • 24