Exemple #1
0
 private static void MakeNoiseMethod(StaticAnimal animal)
 {
     Console.WriteLine("meow");
 }
Exemple #2
0
        private static void ComplainMethod(StaticAnimal animal)
        {
            var tmp = (animal as StaticCat).Hungry ? "Tuna" : "F off";

            Console.WriteLine(tmp);
        }
Exemple #3
0
        protected static void ComplainMethod(StaticAnimal animal)
        {
            var tmp = (animal as StaticGiraffe).Sore ? "Blah" : "All good";

            Console.WriteLine(tmp);
        }
Exemple #4
0
 public static void MakeNoiseMethod(StaticAnimal animal)
 {
     Console.WriteLine();
 }
Exemple #5
0
 public static void ComplainMethod(StaticAnimal animal)
 {
     Console.WriteLine("TAXES");
 }
Exemple #6
0
        static void Main(string[] args)
        {
            Animal animal = new Giraffe();

            animal.Complain();
            animal.MakeNoise();

            animal = new Cat();
            animal.Complain();
            animal.MakeNoise();

            Dog dog = new Dog();

            dog.Complain();
            dog.MakeNoise();

            animal = dog;
            animal.Complain();
            animal.MakeNoise();

            Console.WriteLine("------------------------STATIC NEXT");

            //StaticAnimal animal2 = StaticGiraffe.Create();
            //animal2.Complain(animal2);
            //animal2.MakeNoise(animal2);

            //animal2 = StaticCat.Create();
            //animal2.Complain(animal2);
            //animal2.MakeNoise(animal2);

            //StaticDog dog2 = StaticDog.Create();
            //dog2.Complain(dog2);
            //StaticDog.MakeNoise(dog2);

            //animal2 = dog2;
            //animal2.Complain(animal2);
            //animal2.MakeNoise(animal2);

            StaticAnimal animal2 = StaticGiraffe.Create();

            animal2.VTable.Complain(animal2);
            animal2.VTable.MakeNoise(animal2);

            animal2 = StaticCat.Create();
            animal2.VTable.Complain(animal2);
            animal2.VTable.MakeNoise(animal2);

            StaticDog dog2 = StaticDog.Create();

            dog2.VTable.Complain(dog2);
            StaticDog.MakeNoise(dog2);

            animal2 = dog2;
            animal2.VTable.Complain(animal2);
            animal2.VTable.MakeNoise(animal2);

            Console.WriteLine("multiple");

            StaticBrownGiraffe bg = StaticBrownGiraffe.Create();
            StaticAnimal       ag = (StaticAnimal)bg;
            StaticGiraffe      sg = (StaticGiraffe)bg;

            StaticBrownGiraffe.ComplainMethod(bg);
            ag.VTable.Complain(bg);
            sg.VTable.Complain(bg);

            Console.ReadLine();
        }