Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0072

'event' : cannot override; 'method' is not an event

An event can only override another event.

The following sample generates CS0072:

// CS0072.cs
delegate void del();

class Test1
{
   public virtual event del MyEvent;
   public virtual void VMeth()
   {
   }

   public void FireAway()
   {
      if (MyEvent != null)
         MyEvent();
   }
}

class Test2 : Test1
{
   public override event del VMeth   // CS0072
   // uncomment the following lines to resolve
   // public override event del MyEvent
   {
      add
      {
         VMeth += value;
         // MyEvent += value;
      }
      remove
      {
         VMeth -= value;
         // MyEvent -= value;
      }
   }

   public static void Main()
   {
   }
}
Show:
© 2015 Microsoft