7.11

---恢复内容开始---

1、多播委托:每个委托都只包含一个方法调用,调用委托的次数和调用方法的次数相同。多播委托就是一个包含多个方法的委托称为多播委托。

class MyEvent 
    {
        public event EventHandler<EventArgs> OnInput; 
        public void WaitInput()
        {
            while (true)
            {
                if (Console.ReadLine() == "x")
                    OnInput(this, new EventArgs()); 
            }
        }2019-07-11
    }
    class Program
    {
        static void Main(string[] args)
        {
            MyEvent Evt = new MyEvent();
            Evt.OnInput += On_Input;
            Evt.WaitInput();
        }
private static void On_Input(object sender, EventArgs e) { Console.WriteLine("你触发了‘X’!"); } }

 

 

---恢复内容结束---

posted @ 2019-07-11 16:00  碍人眼  阅读(209)  评论(0)    收藏  举报