Пример #1
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            CarDealer dealer   = new CarDealer();
            Consumer  consumer = new Consumer("张三");



            //  WeakEventManger<CarDealer, CarInfoEventArgs>.AddHandler(dealer, "newCarInfo", consumer.NewCarIsHere);



            dealer.newCarEventHander += consumer.NewCarIsHere;

            dealer.NewCar("兰博基尼");



            dealer.NewCar("雪夫兰");
            var sesstion = new Consumer("王五");

            dealer.newCarEventHander += sesstion.NewCarIsHere;

            dealer.NewCar("别克");
            dealer.newCarEventHander -= sesstion.NewCarIsHere;



            Console.ReadLine();
        }
Пример #2
0
        static void Main(string[] args)
        {
            var dealer   = new CarDealer();
            var valtteri = new Consumer("Valtteri");

            dealer.NewCarInfo += valtteri.NewCarIsHere;
            dealer.NewCar("Williams");

            var max = new Consumer("Max");

            dealer.NewCarInfo += max.NewCarIsHere;
            dealer.NewCar("Mercedes");
            dealer.NewCarInfo -= valtteri.NewCarIsHere;
            dealer.NewCar("Ferrari");
        }
Пример #3
0
        static void Main(string[] args)
        {   
            //连接事件发布程序和订阅器
            var dealer = new CarDealer();
            var michael = new Consumer("Michael");
            //dealer.NewCarInfo+=new EventHandler<CarInfoEventArgs>(michael.NewCarIsHere);
            //等价于
            dealer.NewCarInfo += michael.NewCarIsHere;
            dealer.NewCar("Mercedes");

            var nick = new Consumer("Nick");
            dealer.NewCarInfo += nick.NewCarIsHere;
            dealer.NewCar("Ferrari");
            Console.ReadKey();

        }
Пример #4
0
        static void Main(string[] args)
        {
            var dealer = new CarDealer();

            var daniel = new Consumer("Daniel");

            dealer.NewCarInfo += daniel.NewCarIsHere;

            dealer.NewCar("Mercedes");

            var sebastian = new Consumer("Sebastian");

            WeakEventManager <CarDealer, CarInfoEventArgs> .AddHandler(dealer, "NewCarInfo", sebastian.NewCarIsHere);

            dealer.NewCar("Ferrari");
        }