public void Begin() { Sportcar sportcar = new Sportcar(); Truck truck = new Truck(); List <Car> cars = new List <Car>() { sportcar, truck }; foreach (Car car in cars) { car.Start(); car.Accelerate(); car.Boost(); } }
public void Casting() { Car sportcar = new Sportcar(); Car truck = new Truck(); // Sportcar realsportcar = (Sportcar)sportcar; /* * bool isSportcar = sportcar is Sportcar; * * if(isSportcar) * { * Car newcar = (Car)sportcar; * } */ /* * Sportcar newcar = sportcar as Sportcar; * if(newcar != null) * { * * } */ }