<p>In C#, what is the difference (if any) between these two lines of code?</p>

<pre><code>tmrMain.Elapsed += new ElapsedEventHandler(tmrMain_Tick);
</code></pre>

<p>and</p>

<pre><code>tmrMain.Elapsed += tmrMain_Tick;
</code></pre>

<p>Both appear to work exactly the same. Does C# just assume you mean the former when you type the latter?</p>

[{'answer_id': 26884, 'author': 'Orion Edwards', 'author_id': 234, 'author_profile': 'https://Stackoverflow.com/users/234', 'pm_score': 6, 'selected': True, 'text': '<p>I did this</p>\n\n<pre><code>static void Hook1()\n{\n    someEvent += new EventHandler( Program_someEvent );\n}\n\nstatic void Hook2()\n{\n    someEvent += Program_someEvent;\n}\n</code></pre>\n\n<p>And then ran ildasm over the code.<br>\nThe generated MSIL was exactly the same.</p>\n\n<p>So to answer your question, yes they are the same thing.<br>\nThe compiler is just inferring that you want <code>someEvent += new EventHandler( Program_someEvent );</code><br>\n-- You can see it creating the new <code>EventHandler</code> object in both cases in the MSIL</p>\n'}, {'answer_id': 26893, 'author': 'Ray', 'author_id': 233, 'author_profile': 'https://Stackoverflow.com/users/233', 'pm_score': 2, 'selected': False, 'text': "<p>I don't think there's any difference. Certainly resharper says the first line has redundant code.</p>\n"}, {'answer_id': 26895, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': -1, 'selected': False, 'text': '<p>I think the one way to really tell would be to look at the MSIL produced for the code.. Tends to be a good acid test..</p>\n\n<p>I have funny concerns that it may somehow mess with GC.. Seems odd that there would be all the overhead of declaring the new delegate type if it never needed to be done this way, you know?</p>\n'}, {'answer_id': 26913, 'author': 'Timbo', 'author_id': 1810, 'author_profile': 'https://Stackoverflow.com/users/1810', 'pm_score': 0, 'selected': False, 'text': "<p>Wasn't the <code>new XYZEventHandler</code> require until C#2003, and you were allowed to omit the redundant code in C#2005?</p>\n"}, {'answer_id': 26919, 'author': 'denis phillips', 'author_id': 748, 'author_profile': 'https://Stackoverflow.com/users/748', 'pm_score': 2, 'selected': False, 'text': '<p>It used to be (.NET 1.x days) that the long form was the only way to do it. In both cases you are newing up a delegate to point to the Program_someEvent method.</p>\n'}, {'answer_id': 27048, 'author': 'Andrei Rînea', 'author_id': 1796, 'author_profile': 'https://Stackoverflow.com/users/1796', 'pm_score': 2, 'selected': False, 'text': '<p>A little offtopic :</p>\n\n<p>You could instantiate a delegate <code>(new EventHandler(MethodName))</code> and (if appropriate) reuse that instance.</p>\n'}]
['https://Stackoverflow.com/questions/26877', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/369/']