예제 #1
0
        public void Casting()
        {
            Car sportCar = new SportCar();
            Car truck    = new Truck();

            SportCar castedSportCar = sportCar as SportCar;

            if (castedSportCar != null)
            {
                castedSportCar.DisplayInfo();
            }
        }
예제 #2
0
        public void Begin()
        {
            Car sportCar = new SportCar();
            Car truck    = new Truck();

            List <Car> cars = new List <Car>
            {
                sportCar, truck
            };

            foreach (Car car in cars)
            {
                car.Start();
                car.Accelerate();
                car.Boost();
            }
        }