Пример #1
0
        private static void Main(string[] args)
        {
            // A set/hierarchy of classes
            // Defined below

            var baseClass        = new BaseClass();
            var derivedOverride  = new DerivedOverride();
            var derivedNew       = new DerivedNew();
            var derivedOverWrite = new DerivedOverwrite();

            // Here we call the "Name" method for all of the classes to see if they call
            // their own implementation or the base class' implementation.
            baseClass.Name();
            derivedOverride.Name();
            derivedNew.Name();
            derivedOverWrite.Name();

            // When they are cast back to the base class, 3 of the 4 calls the impletementation
            // from the base class.
            //All except for teh Overriden name method.
            Console.ReadLine();
            baseClass.Name();
            derivedOverride.Name();
            ((BaseClass)derivedNew).Name();
            ((BaseClass)derivedOverWrite).Name();
            Console.ReadLine();

            var t1 = typeof(BaseClass);

            Console.WriteLine(t1.Name);
            Console.WriteLine(t1.Assembly);
            Console.ReadLine();
        }
Пример #2
0
        private static void Main(string[] args)
        {
            var baseClass = new BaseClass();
            var derivedOverride = new DerivedOverride();
            var derivedNew = new DerivedNew();
            var derivedOverWrite = new DerivedOverwrite();

            baseClass.Name();
            derivedOverride.Name();
            derivedNew.Name();
            derivedOverWrite.Name();

            Console.ReadLine();
            baseClass.Name();
            derivedOverride.Name();
            ((BaseClass) derivedNew).Name();
            ((BaseClass) derivedOverWrite).Name();
            Console.ReadLine();

            var t1 = typeof (BaseClass);
            Console.WriteLine(t1.Name);
            Console.WriteLine(t1.Assembly);
        }
        private static void Main(string[] args)
        {
            var baseClass        = new BaseClass();
            var derivedOverride  = new DerivedOverride();
            var derivedNew       = new DerivedNew();
            var derivedOverWrite = new DerivedOverwrite();

            baseClass.Name();
            derivedOverride.Name();
            derivedNew.Name();
            derivedOverWrite.Name();

            Console.ReadLine();
            baseClass.Name();
            derivedOverride.Name();
            ((BaseClass)derivedNew).Name();
            ((BaseClass)derivedOverWrite).Name();
            Console.ReadLine();

            var t1 = typeof(BaseClass);

            Console.WriteLine(t1.Name);
            Console.WriteLine(t1.Assembly);
        }