예제 #1
0
 public void CheckCurrentSpeed(Car sender, int currentSpeed)
 {
     if (currentSpeed > maximumAllowedSpeed)
     {
         Console.WriteLine(
             "Sergeant Petrento: Your car with number \"{0}\" exceeded the maximum allowed speed({1}).",
             sender.Number, currentSpeed);
     }
 }
예제 #2
0
        static void Main(string[] args)
        {
            Car car = new Car("AA2233F");
            Car carNumber2 = new Car("BF5533A");
            Policeman policeman = new Policeman(90);

            car.CurrentSpeedChanged += CurrentSpeedChangedEventHandler;
            carNumber2.CurrentSpeedChanged += CurrentSpeedChangedEventHandler;

            car.CurrentSpeedChanged += policeman.CheckCurrentSpeed;
            carNumber2.CurrentSpeedChanged += policeman.CheckCurrentSpeed;

            for (int i = 0; i < 17; i++)
            {
                car.SpeedUp(i);
                carNumber2.SpeedUp(1);
            }
            Console.WriteLine("Before sleep");
            System.Threading.Thread.Sleep(5000);
            Console.WriteLine("After sleep");
        }
예제 #3
0
 public static void CurrentSpeedChangedEventHandler(Car car, int speed)
 {
     Console.WriteLine("Speed of {0} car is {1}", car.Number, speed);
 }