示例#1
0
        static void Main(string[] args)
        {
            Animal abAnimal = new Animal();

            abAnimal.Name = "Animal";
            abAnimal.Age  = 10;
            abAnimal.toSleep();
            abAnimal.makeSound();
            abAnimal.toFeed();
            abAnimal.makeSound(); // must show a Message like "Animal is not hungry"
            Console.WriteLine("\n");

            Bird canary = new Bird("Julia", 5);

            canary.Age = 8;
            canary.toSleep();
            canary.makeSound();
            canary.toFeed();
            canary.makeSound();
            Console.WriteLine("Info about Bird: {0}\n", canary);


            Cat kisa = new Cat("Murka", 2, true);

            kisa.mammalRacion();
            kisa.makeSound();
            Console.WriteLine("Info about Cat: {0}\n", kisa);

            Hamster homa = new Hamster("Katya", 1, false);

            homa.mammalRacion();
            homa.makeSound();
            homa.toFeed();
            Console.WriteLine("Info about Homster: {0}\n", homa);

            Vorona.createVorona("KAtya", 7, "Australia");

            abAnimal.animalAmount();

            Console.ReadLine();
        }
示例#2
0
        static void Main(string[] args)
        {
            Cat c1 = new Cat(true);
            Cat c2 = new Cat(true);
            Cat c3 = new Cat(true);
            Cat c4 = new Cat(true);

            Hamster h1 = new Hamster(true);
            Hamster h2 = new Hamster(true);

            Feeder feeder1 = new Feeder("Katya", 18, "Female");
            Feeder feeder2 = new Feeder("Stas", 19, "Male");

            Feeder[] feeders = new Feeder[5];

            feeders[0] = feeder1;
            feeders[1] = feeder2;

            //Animal[] animals = new lab1.Animal[] { c1, c2, h1, h2 };
            Cat[] cats = new Cat[] { c1, c2, c3, c4 };

            /*
             * Feeder feeder1 = new Feeder("Katya");
             * Feeder feeder2 = new Feeder("Stas");
             * BigZoo zoo1 = new BigZoo(feeder1);
             * SmallZoo zoo2 = new SmallZoo(feeder2);
             * feeder1.Feeding();
             * feeder2.Feeding();
             *
             * Cat c = new lab1.Cat(false);
             * Console.WriteLine("\nRacion of cat: \n");
             * c.Racion();
             * c.SpecialRacion("milk");
             *
             */

            //JsonSerial(feeder1, "obj.json");
            XmlSerial(cats);
            Console.ReadKey();
        }
示例#3
0
        static void Main(string[] args)
        {
            Cat c1 = new Cat(true);
            Cat c2 = new Cat(true);
            Cat c3 = new Cat(true);
            Cat c4 = new Cat(true);

            Hamster h1 = new Hamster(true);
            Hamster h2 = new Hamster(true);

            /*
             * Feeder feeder1 = new Feeder("Katya", 18, "Female");
             * Feeder feeder2 = new Feeder("Stas", 19, "Male");
             *
             * Feeder[] feeders = new Feeder[5];
             *
             * feeders[0] = feeder1;
             * feeders[1] = feeder2;
             *
             * //Animal[] animals = new lab1.Animal[] { c1, c2, h1, h2 };
             * Cat[] cats = new Cat[] { c1, c2, c3, c4 };
             */

            /*
             * Feeder feeder1 = new Feeder("Katya");
             * Feeder feeder2 = new Feeder("Stas");
             * BigZoo zoo1 = new BigZoo(feeder1);
             * SmallZoo zoo2 = new SmallZoo(feeder2);
             * feeder1.Feeding();
             * feeder2.Feeding();
             */
            /*
             * Animal[] animals = new lab1.Animal[] { c1, c2, h1, h2 };
             * Console.WriteLine("\nRacion of cat: \n");
             * c1.Racion();
             * c1.SpecialRacion("milk");
             * Console.WriteLine(animals.Length);
             */
            CatList <Cat> cList = new CatList <Cat>();

            cList.AddToWeakRefList(c1);
            cList.AddToWeakRefList(c2);
            cList.AddToWeakRefList(c3);
            cList.AddToWeakRefList(c4);


            GC.Collect();
            GC.WaitForPendingFinalizers();

            WeakReference wr = WR();

            Console.WriteLine("Is first object alive : " + wr.IsAlive.ToString());

            GC.Collect(2, GCCollectionMode.Forced);

            Console.WriteLine("Is first object alive : " + wr.IsAlive.ToString());

            cList.Dispose();
            Console.WriteLine("List does not exist: " + (cList.wrList == null));// Ccылка  на список null
            Console.WriteLine(cList.ToString());
            Console.ReadKey();
        }