示例#1
0
        static void Main2(string[] args)
        {
            Calculator calculator = new Calculator();

            //事件触发者
            CalcMethod method = new CalcMethod();

            //事件绑定,订阅事件
            calculator.CalcEvent += method.Add;
            calculator.Calc(100, 200);

            calculator.CalcEvent += method.Substract;
            calculator.Calc(100, 200);

            //事件注销
            calculator.CalcEvent -= method.Add;
            calculator.Calc(100, 200);
            Console.ReadKey();
        }
示例#2
0
        static void Main2(string[] args)
        {
            Calculator calculator = new Calculator();

            //事件触发者
            CalcMethod method = new CalcMethod();

            //事件绑定,订阅事件
            calculator.CalcEvent += method.Add;
            calculator.Calc(100, 200);

            calculator.CalcEvent += method.Substract;
            calculator.Calc(100, 200);

            //事件注销
            calculator.CalcEvent -= method.Add;
            calculator.Calc(100, 200);
            Console.ReadKey();
        }