static void Main(string[] args) { CarCollection <Car> carCollection = new CarCollection <Car>(); carCollection.AddCar(new Car("Toyota", 2010)); carCollection.AddCar(new Car("Ford", 2012)); carCollection.AddCar(new Car("Nissan", 2014)); Console.WriteLine($"Name: {carCollection[1].name}\nYear: {carCollection[1].year}"); Console.WriteLine(new string('-', 30)); Console.WriteLine(carCollection.Count); Console.WriteLine(new string('-', 30)); carCollection.Clear(); Console.WriteLine(carCollection.Count); }
static void Main(string[] args) { Car car = new Car("lada", 1994); Car car1 = new Car("lada", 1995); CarCollection <Car> carCollection = new CarCollection <Car>(); carCollection.Add(car); carCollection.Add(car1); carCollection.Add(new Car("bmw", 2000)); Console.WriteLine("Машин в коллекции: " + carCollection.Count); Console.WriteLine("Машин в коллекции подиндексом 1:" + carCollection[1]); Console.WriteLine("Коллекция: " + carCollection.ToString()); Console.WriteLine(new string('-', 20) + "\n Коллекция после очистки"); carCollection.Clear(); Console.WriteLine("Машин в коллекции: " + carCollection.Count); Console.WriteLine(carCollection.ToString()); Console.ReadKey(); }
static void Main(string[] args) { CarCollection <string, int> carCollection = new CarCollection <string, int>(); carCollection.AddCar("Honda", 2019); carCollection.AddCar("Mazeratti", 2018); carCollection.AddCar("Lada", 1985); carCollection.AddCar("Mersedes", 2015); carCollection.AddCar("Tesla", 2017); carCollection.AddCar("Opel", 1987); for (int i = 0; i < carCollection.Count; i++) { Console.WriteLine("[{0}]: " + carCollection[i], i); } Console.WriteLine(new string('-', 20)); Console.WriteLine("Number of cars added to the collection: " + carCollection.Count); carCollection.Removal(); Console.WriteLine("Number of cars after removal: " + carCollection.Count); Console.ReadKey(); }