Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I new-up a new delegate or just add the method to an event?

Tags:

c#

I don't understand what the difference between these 2 variations are. What is the pros/cons of each approach?

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

2.  a.MyEvent += FireEvent;
like image 789
noctonura Avatar asked Aug 07 '09 21:08

noctonura


1 Answers

The first one works in all versions of C# while the second only works on 2.0 and above. If you need your to compile you code with C# 1.0 compiler, go with the first one; otherwise, I'd use the more concise version. The generated code should be identical in both cases.

like image 188
mmx Avatar answered Oct 16 '22 03:10

mmx