Adding to an event with or without "new."

Posted on 2008-11-15
Last Modified: 2012-05-05
Given the following code:

public delegate void MyDelegate();
class MyClass {
      public event MyDelegate MyEvent;
      public void MyFunction() {

... In most online articles that I've read that explain how events work in C#, the author instructs the programmer to add MyFunction to MyEvent using the following syntax:

MyEvent += new MyDelegate(MyFunction);

However, I have ALWAYS been able to just do this:

MyEvent += MyFunction;

Can someone please explain to me the difference between the two, and why I should ever want to use the first method?

I prefer the second method because it's more concise, and because it looks syntactically the same as the method for *removing* a function from an event, i.e. MyEvent -= MyFunction.

Question by:MiloDC
    LVL 26

    Accepted Solution

    As per MSDN article there is no difference between the two methods
    And the shortcut that you have been using has been added in the 2.0 framework

    The only argument that i will be giving for using the syntax with new is that it will indicate which delegate i am referencing to (more readable).
    I will prefer readability over lesser code as in longer run for code maintenance readable code is better than shorter code

    Author Comment

    OK, so it's necessary to do it the first way ("new") only in C# 1.0.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now