Exemplo n.º 1
0
        public static void Show()
        {
            UseEventArgs event_args      = new UseEventArgs();
            Friend       friend_zhangsan = new Friend("张三");
            Friend       friend_lisi     = new Friend("李四");

            event_args.MarrayEvent += new MsgEventHander(friend_zhangsan.Reply);
            event_args.MarrayEvent += new MsgEventHander(friend_lisi.Reply);

            event_args.Notice("发出通知"); // 发出通知
        }
Exemplo n.º 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类用于事件的参数");
        }