Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Frog[] frogs = new Frog[5];
            frogs[0] = new Frog("Kermit", 7, "male");
            frogs[1] = new Frog("Kikeriza", 7, "female");
            frogs[2] = new Frog("Muholovka", 5, "female");
            frogs[3] = new Frog("Purgavka", 3, "female");
            frogs[4] = new Frog("Zelenko", 4, "female");

            Dogs[] dogs = new Dogs[5];
            dogs[0] = new Dogs("Sharo", 9, "male");
            dogs[1] = new Dogs("Sharik", 11, "male");
            dogs[2] = new Dogs("Murdjo", 7, "male");
            dogs[3] = new Dogs("Minka", 10, "female");
            dogs[4] = new Dogs("Lili", 8, "female");

            Cats[] cats = new Cats[5];
            cats[0] = new Kitten("Maca", 11);
            cats[1] = new Kitten("Puffi", 12);
            cats[2] = new TomCat("Chocho", 15);
            cats[3] = new TomCat("James", 10);
            cats[4] = new TomCat("Blacky", 17);

            var frogsAverageAge = frogs
                                  .Average(frog => frog.Age);

            var dogsAverageAge = dogs
                                 .Average(dog => dog.Age);

            var catsAverageAge = cats
                                 .Average(cat => cat.Age);

            Console.WriteLine("The average age of the frogs is {0}", frogsAverageAge.ToString());
            Console.WriteLine();

            Console.WriteLine("The average age of the dogs is {0}", dogsAverageAge.ToString());
            Console.WriteLine();

            Console.WriteLine("The average age of the cats is {0}", catsAverageAge.ToString());
            Console.WriteLine();
        }
Ejemplo n.º 2
0
        static void Main()
        {
            Dog dog = new Dog("Dark", 5, true);

            Console.WriteLine(dog);

            Frog frog = new Frog("Jaburana", 3, false);

            Console.WriteLine(frog);

            Kitten kitten = new Kitten("Pisana", 2);

            Console.WriteLine(kitten);

            Tomcat tomcat = new Tomcat("Tom", 2);

            Console.WriteLine(tomcat);

            Dog[] dogs = new Dog[]
            {
                new Dog("Dark", 2, true),
                new Dog("Mark", 1, true),
                new Dog("Vark", 2, true),
                new Dog("Lara", 3, false)
            };
            Frog[] frogs = new Frog[]
            {
                new Frog("Jaburan4o", 1, true),
                new Frog("Jab4o", 2, true),
                new Frog("Jaja", 4, false),
                new Frog("Jaburana", 4, false),
            };

            Cat[] cats = new Cat[]
            {
                new Cat("Street Excellent", 3, false),
                new Cat("Home Excellent", 5, false),
                new Cat("Persiiko", 1, true),
                new Cat("Garfield", 7, true)
            };

            Kitten[] kittens = new Kitten[]
            {
                new Kitten("Pisana", 3),
                new Kitten("Pis", 10),
                new Kitten("Pisun", 6),
                new Kitten("Pissss", 2),
                new Kitten("MacPis", 4),
            };

            Tomcat[] tomcats = new Tomcat[]
            {
                new Tomcat("Kotio", 5),
                new Tomcat("Gosho", 4),
                new Tomcat("Pesho", 8)
            };

            double dogsAverageAge = dogs.Average(x => x.Age);
            double frogAverageAge = frogs.Average(x => x.Age);
            double catAverageAge  = cats.Average(x => x.Age);

            Console.WriteLine(dogsAverageAge);
            Console.WriteLine(frogAverageAge);
            Console.WriteLine(catAverageAge);



            //или с метод в Animal
            //double dogsAverageAge = Animal.AverageAge(dogs);
        }