Exemplo n.º 1
0
        internal static void SomeMethod()
        {
            Console.WriteLine("-----> starting Example2CastOnTheFly.SomeMethod <-----");

            SomeBaseClass blah = new SomeDerivedClass();

            // this one goes to the method that takes the base class
            TellMeWhoYouAre(blah);

            // this one goes to the over loaded method
            TellMeWhoYouAre((dynamic)blah);

            // without dynamic - I have to see what kind it is
            if (blah is SomeBaseClass)
            {
                if (blah is SomeDerivedClass)
                {
                    TellMeWhoYouAre((SomeDerivedClass)blah);
                }
                else
                {
                    TellMeWhoYouAre(blah); // base class always goes last
                }
            }

            Console.WriteLine("-----> done Example2CastOnTheFly.SomeMethod <-----");
        }
Exemplo n.º 2
0
 private static void TellMeWhoYouAre(SomeDerivedClass blahDerived)
 {
     Console.WriteLine($"blahDerived.SomeData: {blahDerived.SomeData}");
 }