Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 9 down vote accepted

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.

share|improve this answer
add comment

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

share|improve this answer
    
+1 - It is indeed to avoid having to redeclare the delegate. –  Karthik Sreenivasan Feb 21 '12 at 4:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.