private static void Main() { var car = new CarCollection <string, int>(2, new Tuple <string, int>("BMW", 2020), new Tuple <string, int>("Tesla", 2010)); car.Add("Audi", 2020); Console.WriteLine("Before deleting:\n"); for (var i = 0; i < car.Size; i++) { Console.WriteLine(car[i].Item1 + " - " + car[i].Item2); } car.DeleteAll(); car.Add("Honda", 2015); Console.WriteLine("\nAfter deleting and adding new element:"); for (var i = 0; i < car.Size; i++) { Console.WriteLine(car[i].Item1 + " - " + car[i].Item2); } Console.ReadKey(); }
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(); }