コード例 #1
0
ファイル: Program.cs プロジェクト: xs2ranjeet/13ns9-1spr
 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
ファイル: Program.cs プロジェクト: xs2ranjeet/13ns9-1spr
        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
ファイル: Program.cs プロジェクト: xs2ranjeet/13ns9-1spr
 public static void CurrentSpeedChangedEventHandler(Car car, int speed)
 {
     Console.WriteLine("Speed of {0} car is {1}", car.Number, speed);
 }