static void Main(string[] args)
        {
            MyDelegate myDelegate = new MyDelegate();

            myDelegate.Show();

            ListExtend list = new ListExtend();

            list.Show();
        }
Beispiel #2
0
 static void Main(string[] args)
 {
     {
         MyDelegate myDelegate = new MyDelegate();
         myDelegate.Show();
     }
     {
         ListExtend test = new ListExtend();
         test.Show();
     }
     {
         Cat cat = new Cat();
         cat.MiaoDelegateHandlerEvent += new MiaoDelegate(new Baby().Cry);
         cat.MiaoDelegateHandlerEvent += new MiaoDelegate(new Mother().Wispher);
         cat.MiaoNewEvent();
         Console.WriteLine("***************************");
     }
     Console.Read();
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("********************Delegate + Event***********************");

                {
                    MyDelegate myDelegate = new MyDelegate();

                    myDelegate.Show();
                }
                {
                    ListExtend test = new ListExtend();
                    test.Show();
                }

                {
                    Console.WriteLine("*************************Event********************");
                    {
                        Cat cat = new Cat();
                        cat.Miao();
                    }
                    {
                        Cat cat = new Cat();

                        cat.miaoDelegateHandler += new MiaoDelegate(new Mouse().Run);
                        cat.miaoDelegateHandler += new MiaoDelegate(new Baby().Cry);
                        cat.miaoDelegateHandler += new MiaoDelegate(new Mother().Wispher);
                        cat.miaoDelegateHandler += new MiaoDelegate(new Father().Roar);
                        cat.miaoDelegateHandler += new MiaoDelegate(new Neighbor().Awake);
                        cat.miaoDelegateHandler += new MiaoDelegate(new Stealer().Hide);
                        {
                            cat.miaoDelegateHandler.Invoke();
                            cat.miaoDelegateHandler = null;
                        }
                        cat.MiaoNew();
                    }

                    {
                        Cat cat = new Cat();

                        cat.miaoDelegateEvent += new MiaoDelegate(new Mouse().Run);
                        cat.miaoDelegateEvent += new MiaoDelegate(new Baby().Cry);
                        cat.miaoDelegateEvent += new MiaoDelegate(new Mother().Wispher);
                        cat.miaoDelegateEvent += new MiaoDelegate(new Father().Roar);
                        cat.miaoDelegateEvent += new MiaoDelegate(new Neighbor().Awake);
                        cat.miaoDelegateEvent += new MiaoDelegate(new Stealer().Hide);

                        {
                            // event 关键字不允许外部直接调用或者赋值
                            // 做了限制

                            //cat.miaoDelegateEvent.Invoke();
                            //cat.miaoDelegateEvent = null;
                        }

                        cat.MiaoNew();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.Read();
        }