传递方法时 要用方法类型 (委托)

事件委托 的使用

简单例子

有个学生 有个老师  老师 通过监控 看学生玩游戏

 

代码
pubic delegate void PlayHandler();//委托 用于联系事件的函数

public class employee

{
public event PlayHandler PlayGame;//事件
public void games()
{
if(PlayGame!=null
{
PlayGame();
}
}
 

}
public class admin
{
public void nofy()
{
  system.console.write("i looked");
}
}
pubic class test()
{
  public void main()
{
  employee e=new employee();
    admin a=new admin();
e.PlayName+=new PlayHandler(a.nofy);
e.games();
}
}

 

 

 

相关文章:

  • 2022-02-15
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
  • 2021-12-14
  • 2022-01-15
猜你喜欢
  • 2021-12-26
  • 2021-06-01
  • 2022-03-08
  • 2021-09-23
  • 2021-08-20
  • 2022-12-23
  • 2021-12-12
相关资源
相似解决方案