예제 #1
0
        public static void Show()
        {
            UseEventHandler event_handler   = new UseEventHandler();
            Friend          friend_zhangsan = new Friend("张三");
            Friend          friend_lisi     = new Friend("李四");

            event_handler.MarrayEvent += new EventHandler(friend_zhangsan.Reply);
            event_handler.MarrayEvent += new EventHandler(friend_lisi.Reply);

            event_handler.Notice("发出通知"); // 发出通知
        }
예제 #2
0
        public static void Show()
        {
            Util.PrintTitle(delegate() { DelegateUsage.Show(); }, "委托");
            Util.PrintTitle(delegate() { DelegateChain.Show(); }, "委托链");
            Util.PrintTitle(delegate() { BridegroomEven.Show(); }, "事件");

            /* 在类外调用事件是不允许的 */
            //bridegroomeven bridegroom_even = new bridegroomeven();
            //friend friend_zhaoliu = new friend("赵六");
            //bridegroom_even.marryevent += friend_zhaoliu.reply;
            //bridegroom_even.marryevent("msg");

            /* 可以在类外调用委托 */
            //DelegateChain.DelegateTest dt_static = new DelegateChain.DelegateTest(DelegateChain.Method1);
            //dt_static();

            Util.PrintTitle(delegate() { UseEventHandler.Show(); }, "EventHandler委托类");
            Util.PrintTitle(delegate() { UseEventArgs.Show(); }, "自定义EventArgs类用于事件的参数");
        }