public PeopleTwo(Ios ios)
 {
     ios.IosEvent += () =>
     {
         Console.WriteLine("yi said descrementer");
     };
 }
Esempio n. 2
0
 public PeopleJia(Ios ios)
 {
     ios.IosEvent += () =>
     {
         Console.WriteLine("jia said desCrementer");
     };
 }
Esempio n. 3
0
        static void Main(string[] args)
        {  //委托和事件的比较,事件是阉割的委托实例
            Ios ios = new Ios(3500);

            ios.Iosdele  = () => { Console.WriteLine("delegate1"); };
            ios.Iosdele += () => { Console.WriteLine("delegate2"); };
            ios.Iosdele += () => { Console.WriteLine("delegate3"); };
            ios.Iosdele.Invoke();//委托实例可以在类外被调用,而事件不可以
            //ios.IosEvent = () => { Console.WriteLine("event0"); };
            ios.IosEvent += () => { Console.WriteLine("event1"); };
            ios.IosEvent += () => { Console.WriteLine("event2"); };
            ios.IosEvent -= () => { Console.WriteLine("event2"); };

            //标准的点击事件
            ClickEvent     en        = new ClickEvent();
            ClickEventArgs eventArgs = new ClickEventArgs();

            en.clickEvent += Btn_click;
            en.Click(eventArgs);
            //利用观察者模式案例
            PeopleJia jia = new PeopleJia(ios);
            PeopleTwo two = new PeopleTwo(ios);

            ios.Price = 3200;
            Console.ReadKey();
        }