Eventhandlers, C#, VS2005

  • Thread starter Thread starter Gina_Marano
  • Start date Start date
G

Gina_Marano

help, help, help.

The microsoft documentation is getting me in a tizzy.

What is the difference between the following:

timer1.Tick += new System.EventHandler(timer1_Tick);

&

timer1.Tick += this.timer1_Tick;

They both compile and look like they work the same.

~Gina~
 
Gina_Marano said:
help, help, help.

The microsoft documentation is getting me in a tizzy.

What is the difference between the following:

timer1.Tick += new System.EventHandler(timer1_Tick);

&

timer1.Tick += this.timer1_Tick;

They both compile and look like they work the same.

~Gina~

The are the same... It's a new feature in C# 2.0.
 
thanks a lot tom.

Which one is old school and which one is new school?

~Gina~
 
Gina_Marano said:
thanks a lot tom.

Which one is old school and which one is new school?

~Gina~

Sorry... The shorter:

timer1.Tick += this.timer1_Tick

Is the new method. It's really just shorter syntax for the "+= new"
version.
 
It's just a syntax shortcut, if you check the compiled code, it is
compiled into the same IL..

Regards.
 
Gina_Marano said:
thanks a lot tom.

Which one is old school and which one is new school?

~Gina~

Hi Gina,

It's a preference thing. What ever you feel comfortable with using. The
compiler can infer what you're trying to do, rather than you explicitally
tell it what you want it to do... so if you feel comfortable reading your
code, and knowing what the compiler is going to do when it reaches that
line (i.e. knowing that it will infer the new System.EventHandler(...)
part), then stick to short-hand.
 
thanks Tom and everyone for helping clarify this.

I come from the Delphi realm where the specifics are sometimes hidden
from you and you start taking them for granted.

~Gina~
 
Jianwei said:
It's just a syntax shortcut, if you check the compiled code, it is
compiled into the same IL..

Yes, I know. I didn't mean to imply otherwise.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top