コード例 #1
0
ファイル: Program.cs プロジェクト: Stargik/C-Base
        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);
        }
コード例 #2
0
        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();
        }