示例#1
1
        static void Main(string[] args)
        {
            ICar car = new M3();

            car.CarStopped += new EventHandler(OnCarStopped);
            car.Start();
            car.PressAccelerator(10);
            car.PressBrake(10);
        }
        private static void CarInterface()
        {
            ICar[] cars = { new M3      {
                                Color = Color.Silver
                            },
                            new Hooptie {
                                Color = Color.Black
                            } };

            foreach (var car in cars)
            {
                PrintInfo(car);
                car.Start();
                car.PressAccelerate(2);
                car.PressAccelerate(10);
                car.PressBrake(2);
                car.PressBrake(10);
            }

            Console.WriteLine("Here is a new BMW M3");
            ICar m3 = new M3();

            m3.Start();

            Console.WriteLine("Here is a new hooptie!");
            Hooptie hooptie = new Hooptie();

            hooptie.Start();
        }
        private static void CarStoppedDelegate()
        {
            ICar car = new M3();

            car.CarStopped += OnCarStopped;

            car.Start();
            car.PressAccelerate(10);
            car.PressBrake(10);
        }