Esempio n. 1
0
        public static void Main()
        {
            Car car = new Car(90);

            car = new FamilyCar(80);
            car = new SportCar(280);
            car = new LuxurySportCar();
            car = new Bulldozer();
            var isTypeOf = car is ICar;

            Car familyCar = new FamilyCar(80);
            //var capacity = familyCar.TrunkCapacity; // we don't have an access
            var capacity = ((FamilyCar)familyCar).TrunkCapacity;

            SportCar sportCar = new SportCar();

            sportCar = new LuxurySportCar();
            isTypeOf = sportCar is ICar;
            //sportCar = new Car(90); // can't do'
            //you can cast detailed object to more generic implicitly

            CastClassTest(sportCar);
            //CastClassTest(car);
            CastClassTest(new LuxurySportCar());
            //CastClassTest(new Bulldozer());

            //CastInterfaceTest(sportCar);
            //CastInterfaceTest(car);
            //CastInterfaceTest(new LuxurySportCar());
            //CastInterfaceTest(new Bulldozer());
        }
Esempio n. 2
0
 private static void CastClassTest(SportCar car)
 {
 }