the main difference in your example is the structure of the method that will be performed. In the first case:
- timer.Tick += new EventHandler(timer_Tick); //event
the method timer_Tick
looks like this:
public void timer_Tick(object sender, EventArgs e)
{
}
so you can use the parameters object sender
and EventArgs e
. What you actually do here is to call the constructor of EventHandler
and you pass a delegate/pointer to a method into it.
Although this structure is given by the Tick
property in your second case:
- timer.Tick += delegate {/to perform my operations on tick/}; //anonymous method
you create an anonymous method and actually hide the parameter with the delegate keyword and you have no access to them. Also you will not be able to call this method from somewhere else. You cannot simulate the firing of the event and you cannot reuse the code.
Here you could use a lambda expression to actually specify the parameters so that you can have access to them:
timer.Tick += (s, e) => { };
The third case:
timer.Tick += Timer_Tick;
is a short version of the first case. Here Visual Studio will infer the correct structure of the method for you without specifying the type of the event. If the method Timer_Tick
that you implement will not match the the structure demanded by Tick
the compiler will complain!
Example:

The delegate Tick
is of type EventHandler . This typespecifies the structure that I wrote in the first case above, you will see it in the documentation. If (as you can see in the picture) the structures of the delegate Tick
and the structure of the Timer_Tick
method do not match you have an error. Note that in this expression:
timer.Tick += Timer_Tick;
Timer_Tick
is just a delegate/a pointer to the method in question which has to be implemented!
For fundamental differences between delegates and events please have a look at this article and this acticle