Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //EventTest e = new EventTest(); /* 实例化对象,第一次没有触发事件 */
            //subscribEvent v = new subscribEvent(); /* 实例化对象 */
            //e.ChangeNum += new EventTest.NumManipulationHandler(v.printf); /* 注册 */
            //e.SetValue(7);
            //e.SetValue(11);
            //Console.Read();
            //PTest p = new PTest();
            ////p.GreetPeople((a, b) => Console.WriteLine(a + b), "早上好", "夏明");
            ////Action<string, string> act = p.ChineseGreeting;
            ////act += p.ChineseGreeting1;
            ////p.GreetPeople(act, "goodmorning", "夏明");
            ////PTest PTest = new PTest();
            ////PTest.MakeGreet += (a, b) => Console.WriteLine(a+b);
            ////PTest.GetTest("小明", "你好");
            //Heater heater = new Heater();
            //Alarm alarm = new Alarm();

            //heater.BoilEvent += alarm.MakeAlert;    //注册方法
            ////heater.BoilEvent += (new Alarm()).MakeAlert;   //给匿名对象注册方法
            //heater.BoilEvent += Display.ShowMsg;       //注册静态方法

            //heater.BoilWater();   //烧水,会

            Heater heater = new Heater();
            Alarm  alarm  = new Alarm();

            heater.Boiled += alarm.MakeAlert;                                //注册方法
            heater.Boiled += (new Alarm()).MakeAlert;                        //给匿名对象注册方法
            heater.Boiled += new Heater.BoiledEventHandler(alarm.MakeAlert); //也可以这么注册
            heater.Boiled += Display.ShowMsg;                                //注册静态方法

            heater.BoilWater();                                              //烧水,会自动调用注册过对象的方法
            Console.Read();
        }
Ejemplo n.º 2
0
        static void Main()
        {
            Heater ht = new Heater();

            ht.BoilWater();
        }