Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Cat d1 = new Cat {
                Species = "Ordinary cat"
            };

            d1.FoodSearch(true);

            Mongoose c1 = new Mongoose {
                Species = "Africanian mongoose"
            };

            c1.FoodSearch(true);
            ((water)c1).FoodSearch(true);

            Elephant b1 = new Elephant {
                Species = "Desert Elephant"
            };

            ((ground)b1).FoodSearch(true);
            ((sky)b1).FoodSearch(true);

            Snack k1 = new Snack {
                Species = "Belarusian snack"
            };

            k1.FoodSearch(true);

            Goose g1 = new Goose {
                Species = "Grey goose"
            };

            ((water)g1).FoodSearch(true);
            ((sky)g1).FoodSearch(true);
            ((ground)g1).FoodSearch(true);

            Group <Animal> group = new Group <Animal>();

            group.Push(d1);
            group.Push(c1);
            group.Push(b1);
            group.Push(k1);
            group.Push(g1);
            group.Print();

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Cat d1 = new Cat {
                Species = "Ordinary Cat"
            };

            d1.FoodSearch(true);

            Mongoose c1 = new Mongoose {
                Species = "Africanian mongoose"
            };

            c1.FoodSearch(true);
            ((water)c1).FoodSearch(true);

            Elephant b1 = new Elephant {
                Species = "Desert Elephant"
            };

            ((ground)b1).FoodSearch(true);
            ((sky)b1).FoodSearch(true);

            Snack k1 = new Snack {
                Species = "Belarusian snack"
            };

            k1.FoodSearch(true);

            Goose g1 = new Goose {
                Species = "Grey goose"
            };

            ((water)g1).FoodSearch(true);
            ((sky)g1).FoodSearch(true);
            ((ground)g1).FoodSearch(true);

            Group <Animal> group = new Group <Animal>();

            group.Push(d1);
            group.Push(c1);
            group.Push(b1);
            group.Push(k1);
            group.Push(g1);


            //LINQ

            Console.WriteLine("\nThe first\n");

            var first = group.data.Where(n => n != null && n.Species.Length >= 15).OrderBy(n => n.Species.Length);

            foreach (Animal animal in first)
            {
                Console.WriteLine(animal.Species);
            }

            Console.WriteLine("\nThe second\n");

            var second = from animal in @group.data
                         where animal != null && animal.Species.StartsWith("G")
                         orderby animal.Species descending
                         select animal;

            foreach (Animal animal in second)
            {
                Console.WriteLine(animal.Species);
            }

            Console.WriteLine("\nThe third\n");

            var third = (from animal in @group.data where animal != null && animal.Energy >= 0 select animal).Count();

            Console.WriteLine(third);

            Console.ReadKey();
        }