示例#1
0
文件: Car.cs 项目: ledomone/basd
        public void Casting()
        {
            Car sportCar = new SportCar();
            Car truck    = new Truck();

            SportCar castedSportCar = sportCar as SportCar;

            if (castedSportCar != null)
            {
                castedSportCar.DisplayInfo();
            }
        }
示例#2
0
文件: Car.cs 项目: ledomone/basd
        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();
            }
        }