예제 #1
0
        static void Main()
        {
            Cat tommy = new Cat("Tommy" ,2 ,Sex.male);
            Dog sharo = new Dog("Sharo" , 3 ,Sex.male);
            Frog princess = new Frog("Afrodita" , 5 , Sex.female);
            Kitten milka = new Kitten("Milka" , 4 , Sex.female);
            TomCat tom = new TomCat("Tom" , 1 , Sex.male);
            zooPark = new Animal[] { tommy, sharo ,princess , milka , tom};    // <-- Is this an abstract ? A: maybe calling a array is possible ...

            foreach (var animal in zooPark)
            {
                Console.WriteLine(animal);
                switch (animal.GetType().Name)
                {
                    case "Dog":
                        Dog doggy = animal as Dog;
                        doggy.Talk();
                        break;
                    case "Cat":
                        Cat catty = animal as Cat;
                        catty.Talk();
                        break;
                    case "Frog":
                        Frog frogie = animal as Frog;
                        frogie.Talk();
                        break;
                    default:
                        break;
                }
            }
            CalculateAverageAge();
            Console.WriteLine("\n\r\n\rTo see that condition for male checking of kitten and TOmcat works");
            // See implemented method below
            CheckSexAnimal();
        }
예제 #2
0
        static void Main()
        {
            Cat    tommy    = new Cat("Tommy", 2, Sex.male);
            Dog    sharo    = new Dog("Sharo", 3, Sex.male);
            Frog   princess = new Frog("Afrodita", 5, Sex.female);
            Kitten milka    = new Kitten("Milka", 4, Sex.female);
            TomCat tom      = new TomCat("Tom", 1, Sex.male);

            zooPark = new Animal[] { tommy, sharo, princess, milka, tom };     // <-- Is this an abstract ? A: maybe calling a array is possible ...


            foreach (var animal in zooPark)
            {
                Console.WriteLine(animal);
                switch (animal.GetType().Name)
                {
                case "Dog":
                    Dog doggy = animal as Dog;
                    doggy.Talk();
                    break;

                case "Cat":
                    Cat catty = animal as Cat;
                    catty.Talk();
                    break;

                case "Frog":
                    Frog frogie = animal as Frog;
                    frogie.Talk();
                    break;

                default:
                    break;
                }
            }
            CalculateAverageAge();
            Console.WriteLine("\n\r\n\rTo see that condition for male checking of kitten and TOmcat works");
            // See implemented method below
            CheckSexAnimal();
        }