C#中的子类无法调用父类的事件,可以通过在父类中创建一个方法来调用父类的事件,而子类通过调用父类的方法来触发事件。
class parent
{
protected string name;
public event Handle OnEvent;
protected SendEvent(HandleArgs args)
{
if (OnEvent != null)
{
OnEvent(this, args);
}
}
}
class clild : parent
{
public clild()
{
name = "server1";
}
public void Start()
{
SendEvent(new HandleArgs(State.Start, name));
}
}
class parent
{
protected string name;
public event Handle OnEvent;
protected SendEvent(HandleArgs args)
{
if (OnEvent != null)
{
OnEvent(this, args);
}
}
}
class clild : parent
{
public clild()
{
name = "server1";
}
public void Start()
{
SendEvent(new HandleArgs(State.Start, name));
}
}