static void Main(string[] args) { CarCollection <Auto> auto = new CarCollection <Auto>(); auto.AddCar("Lexus", 200, 60000); auto.AddCar("Mazda", 150, 20000); auto.AddCar("BMW", 210, 40000); auto.SortByPrice(); foreach (Auto item in auto) { Console.WriteLine(item.Name); } Console.WriteLine("Count:{0} ", auto.Count); Console.ReadLine(); }
static void Main(string[] args) { CarCollection <ICar> cars = new CarCollection <ICar>(); Car car = new Car("BMW", 1919); Car car1 = new Car("TT", 1991); SuperCar superCar = new SuperCar("SuperCar", 2019); cars.AddCar(car); cars.AddCar(car1); cars.AddCar(superCar); foreach (var item in cars.GetList()) { Console.WriteLine(item.Name); } Console.WriteLine(); Console.WriteLine(cars[1].Name); Console.WriteLine(cars.Count); cars.Clear(); cars.AddCar(car); cars.AddCar(car1); cars.AddCar(superCar); foreach (var item in cars.GetList()) { Console.WriteLine(item.Name); } Console.WriteLine(); Console.WriteLine(cars[1].Name); Console.WriteLine(cars.Count); Console.ReadKey(); }