Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Queue <Sparrow> queue = new Queue <Sparrow>();

            Sparrow alpha = new Sparrow()
            {
                Name = "Alpha", Weight = 1.0
            };
            Sparrow bravo = new Sparrow()
            {
                Name = "Bravo", Weight = 2.0
            };
            Sparrow charlie = new Sparrow()
            {
                Name = "Charlie", Weight = 3.0
            };

            Console.WriteLine($"{alpha} steps into the queue!");
            queue.Enqueue(alpha);

            Console.WriteLine($"{bravo} steps into the queue!");
            queue.Enqueue(bravo);

            Console.WriteLine($"{charlie} steps into the queue!");
            queue.Enqueue(charlie);

            Sparrow serveFirst = queue.Dequeue();

            serveFirst.Eat();

            Console.WriteLine();
            Console.WriteLine("The other sparrows in the queue dont get to eat! :(");

            foreach (Sparrow sparrow in queue)
            {
                sparrow.Fly();
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Parrot parrot1 = new Parrot(34);

            parrot1.Eat();
            parrot1.Fly();
            parrot1.Talk("Hello there!");
            parrot1.Talk();

            Console.WriteLine();

            Sparrow sparrow1 = new Sparrow()
            {
                Name = "Tom", Weight = 1.5
            };

            sparrow1.Eat();
            sparrow1.Fly();
            sparrow1.ClimbThroughSmallHole();

            Parrot parrot2 = new Parrot(15)
            {
                Name = "Pelle", Weight = 45.6
            };;
            Parrot parrot3 = new Parrot(15)
            {
                Name = "Anna", Weight = 235.6
            };;
            Sparrow sparrow2 = new Sparrow()
            {
                Name = "Mats", Weight = 23.4
            };;

            Bird[] birds = { parrot1, parrot2, sparrow1, parrot3, sparrow2 };

            Console.WriteLine();
            Console.WriteLine("Bird array:");
            Console.WriteLine();

            foreach (Bird bird in birds)
            {
                bird.Eat();
                if (bird is Parrot)
                {
                    Parrot temporaryParrot = (Parrot)bird;

                    //(bird as Parrot).Talk();
                    temporaryParrot.Talk();
                    temporaryParrot.Fly();
                }
                else
                {
                    Console.WriteLine($"{bird.Name} can not talk!");
                }
            }

            Console.WriteLine();

            foreach (Bird bird in birds)
            {
                bird.Die();
            }
        }