Wired EventHandlers

Is there a difference between

Object.Event += new System.EventHandler(EventHandler); Object.Event -= new System.EventHandler(EventHandler); 

and

 Object.Event += EventHandler; Object.Event -= EventHandler; 

? If so, then what?

Don't they both point to methods?

+6
source share
2 answers

Both are exactly the same. But

 Object.Event += EventHandler; Object.Event -= EventHandler; 

The above example compiles only in version 3.0 or later of C #, whereas if you are in version 2.0 or before you can only use the following construction.

 Object.Event += new System.EventHandler(EventHandler); Object.Event -= new System.EventHandler(EventHandler); 

See more at Enter Output . search "Output Type"

+6
source

No, they are exactly the same. The second version is purely a shorthand when the compiler creates an instance of an event handler for you. Just like a simplified property syntax, usage, etc ... all the compiler magic!

See this question:

Difference between posting events using the new EventHandler <T> "and not using the new EventHandler <T>"?

+2
source

Source: https://habr.com/ru/post/889208/


All Articles