【发布时间】:2010-10-19 20:46:57
【问题描述】:
我有一个包含以下事件的基类:
public event EventHandler Loading;
public event EventHandler Finished;
在从这个基类继承的类中,我尝试引发事件:
this.Loading(this, new EventHandler()); // All we care about is which object is loading.
我收到以下错误:
事件 'BaseClass.Loading' 只能出现在 += 或 -= (BaseClass') 的左侧
我假设我无法像其他继承成员一样访问这些事件?
【问题讨论】:
-
Frederik Gheysels 已经回答了这个问题。在 Microsoft Docs 上建议使用相同的做法:How to raise base class events in derived classes (C# Programming Guide) 作为官方的“C# 编程指南”
标签: c# events inheritance