static void Main(string[] args)
        {
            var dealer  = new CarDealer();
            var michael = new Consumer("Michael");

            dealer.NewCarInfo += michael.NewCarIsHere;//订阅事件

            dealer.NewCar("Ferrari");

            var nick = new Consumer("Sebastian");

            dealer.NewCarInfo += nick.NewCarIsHere;

            dealer.NewCar("Mercedes");

            dealer.NewCarInfo -= michael.NewCarIsHere;//注销事件

            dealer.NewCar("Red Bull Racing");


            Console.ReadKey();
        }
Beispiel #2
0
        static void Main()
        {
            var publisher = new CarDealer();

            var michaelConsumer = new Consumer("Michael");

            publisher.NewCarInfo += michaelConsumer.Notify;

            publisher.NewCar("Ferrari");

            var nickConsumer = new Consumer("Sebastian");

            publisher.NewCarInfo += nickConsumer.Notify;

            publisher.NewCar("Mersedes");

            publisher.NewCarInfo -= michaelConsumer.Notify;

            publisher.NewCar("Red Bull Racing");

            Console.ReadLine();
        }