static void Main(string[] args)
        {
            // displaying our object
            Transport MyCar = new Transport(200, 1000, 200, 8);

            MyCar.Display();
            Transport[] MoreCars = { new Transport(250, 1200, 225, 7.4),
                                     new Transport(250, 1200, 225, 7.4),
                                     new Transport(250, 1200, 225, 7.4),
                                     new Transport(250, 1200, 225, 7.4) };
            Console.WriteLine("We produced " + Transport.NumberOfObjects + " \"Transport\" objects");

            FerrariEnzo MyFerrari = new FerrariEnzo(Color.Red);

            FerrariEnzo[] MoreFerrari = { new FerrariEnzo(Color.Blue),
                                          new FerrariEnzo(Color.Yellow),
                                          new FerrariEnzo(Color.Green),
                                          new FerrariEnzo(Color.Navi) };

            Console.WriteLine("We produced " + Transport.NumberOfObjects + " \"Transport\" objects and their descendants");
            Console.ReadKey(true);
            Console.WriteLine();

            for (int i = 0; i < 4; i++)
            {
                Console.WriteLine("The color of this Enzo Ferrari is " + MoreFerrari[i].Color.ToString());
                MoreFerrari[i].Sell();
            }
            Console.ReadKey(true);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            // Отображение нашего транспортного объекта
            Transport MyCar = new Transport(200, 1000, 200, 8);

            MyCar.Display();
            Transport[] MoreCars = { new Transport(250, 1200, 225, 7.4),
                                     new Transport(250, 1200, 225, 7.4),
                                     new Transport(250, 1200, 225, 7.4),
                                     new Transport(250, 1200, 225, 7.4) };
            Console.WriteLine("We produced " + Transport.NumberOfObjects + " \"Transport\" objects");
            Console.WriteLine();

            // Показ наших объектов FerrariEnzo
            FerrariEnzo MyFerrari = new FerrariEnzo(Color.Red);

            FerrariEnzo[] MoreFerrari = { new FerrariEnzo(Color.Red),
                                          new FerrariEnzo(Color.Yellow),
                                          new FerrariEnzo(Color.Green),
                                          new FerrariEnzo(Color.Yellow) };
            Console.WriteLine();

            // Использование событий
            MyFerrari.SellFerrari.Event += new EventHandler(SellFunction);
            for (int i = 0; i < 4; i++)
            {
                MoreFerrari[i].SellFerrari.Event += new EventHandler(SellFunction);
            }
            Console.ReadKey(true);

            // Использование статического метода
            Console.WriteLine("We produced " + FerrariEnzo.NumberOfCars + " Enzo Ferrari.");
            Console.WriteLine("The number of Transport objects and their descendants is " + Transport.NumberOfObjects.ToString());
            Console.ReadKey(true);
            Console.WriteLine();

            for (int i = 0; i < 4; i++)
            {
                Console.WriteLine("The color of this Enzo Ferrari is " + MoreFerrari[i].Color.ToString());
                MoreFerrari[i].Sell();
                Console.WriteLine();
            }

            // Разрушение наших объектов
            Console.WriteLine("Deleting our objects . . .");
            Console.WriteLine("Press any key . . .");
            Console.ReadKey(true);

            MyCar     = null;
            MyFerrari = null;
            for (int i = 0; i < 4; i++)
            {
                MoreCars[i]    = null;
                MoreFerrari[i] = null;
            }

            // Попытка избежать потерь
            Console.WriteLine();
            GC.Collect(10, GCCollectionMode.Forced);
            System.Threading.Thread.Sleep(2000);

            Console.WriteLine("Now the number of our Ferrari is " + FerrariEnzo.NumberOfCars.ToString() + ";");
            Console.WriteLine("The number of Transport objects and their descendants is " + Transport.NumberOfObjects.ToString());
            Console.WriteLine("Press any key . . .");
            Console.ReadKey(true);
        }