共用方式為


編譯器錯誤 CS0068

更新:2007 年 11 月

錯誤訊息

'event': 介面中的事件不能有初始設定式

介面中的事件不能有初始設定式。如需詳細資訊,請參閱介面 (C# 程式設計手冊)

下列範例會產生 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()
   {
   }
}