編譯器錯誤 CS0072
更新:2007 年 11 月
錯誤訊息
'event': 無法覆寫; 'method' 不是事件
事件只能覆寫另一個事件。如需詳細資訊,請參閱事件 (C# 程式設計手冊)。
下列範例會產生 CS0072:
// CS0072.cs
delegate void MyDelegate();
class Test1
{
public virtual event MyDelegate MyEvent;
public virtual void VMeth()
{
}
public void FireAway()
{
if (MyEvent != null)
MyEvent();
}
}
class Test2 : Test1
{
public override event MyDelegate VMeth // CS0072
// uncomment the following lines to resolve
// public override event MyDelegate MyEvent
{
add
{
VMeth += value;
// MyEvent += value;
}
remove
{
VMeth -= value;
// MyEvent -= value;
}
}
public static void Main()
{
}
}