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));
  }
}

相关文章:

  • 2021-05-26
  • 2021-11-17
  • 2022-01-24
  • 2021-05-19
  • 2021-12-01
  • 2021-09-03
猜你喜欢
  • 2022-12-23
  • 2021-10-18
  • 2021-07-30
  • 2021-08-22
  • 2021-05-18
  • 2022-12-23
相关资源
相似解决方案