Example #1
0
        private void DoMammalStuff(Mammal mammal)
        {
            Cow asCow = mammal as Cow;

            if (asCow != null)
            {
                asCow.Stampede();
            }
            else
            {
                mammal.Ambulate();
            }
            if (mammal is Cow)
            {
                Cow cow = (Cow)mammal;
                cow.Stampede();
            }
            else
            {
                mammal.Ambulate();
            }
            mammal.Ambulate();
            var totalSleep = mammal.Sleep();

            mammal.Eat();
            totalSleep += mammal.Sleep();
            Console.WriteLine($"total hours of sleep: {totalSleep}" + "\n");
        }
Example #2
0
        static void Main(string[] args)
        {
            Mammal Bob    = new Mammal(25);
            Dog    George = new Dog(40, "Shepard");
            Cat    Missi  = new Cat(27, "Myaaau");

            Console.WriteLine($"Bob is {Bob.Age} years old");
            Console.WriteLine($"George is {George.Age} years old and he is a {George.Breed} breed.");
            George.WagTail();
            Console.WriteLine($"Missi is {Missi.Age} years old and she like to say {Missi.Myau} ;)");
            int five = 5;

            if (!(five is string))
            {
                Console.WriteLine(five);
            }
        }
Example #3
0
        public void Run()
        {
            var bat   = new Bat();
            var human = new Human();
            var cow   = new Cow();

            Mammal mCow = cow;

            cow.Stampede();
            ((Cow)mCow).Stampede();

            var mammals = new List <Mammal>()
            {
                bat, human, cow
            };

            foreach (var mammal in mammals)
            {
                DoMammalStuff(mammal);
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            // can be done because is not abstract!!!
            Mammal m = new Mammal("Rex");

            Dog dog = new Dog("Jamie");

            dog.Bark();

            // we cannot access protected members
            // dog._name = "Joro";

            Cat cat = new Cat("Misha");

            cat.Meaw();

            Human human = new Human("Stanislava");

            human.Speak("Hello");

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }