This topic has not yet been rated - Rate this topic

Compiler Error CS0068

'event': event in interface cannot have initializer

An event in an interface cannot have an initializer. For more information, see Interfaces (C# Programming Guide).

The following sample generates CS0068:

// CS0068.cs

delegate void MyDelegate();

interface I
{
   event MyDelegate d = new MyDelegate(M.f);   // CS0068
   // try the following line instead
   // event MyDelegate d2;
}

class M
{
   event MyDelegate d = new MyDelegate(M.f);

   public static void f()
   {
   }

   public static void Main()
   {
   }
}
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ