Beispiel #1
0
        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);
        }
Beispiel #2
0
        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();
        }