Should I update a new delegate or just add a method to the event?

I don’t understand what is the difference between these two variations. What are the advantages / disadvantages of each approach?

1.  a.MyEvent += new MyClass.MyEventDelegate(FireEvent);

2.  a.MyEvent += FireEvent;
+5
source share
2 answers

The first works in all versions of C #, and the second only works on 2.0 and higher. If you need you to compile code with the C # 1.0 compiler, go to the first; otherwise, I would use a more compressed version. The generated code should be identical in both cases.

+6
source

Indeed, this is syntactic sugar; the compiler will interpret the code and make delegates for you.

+2
source

All Articles