.assembly extern mscorlib {} .assembly OverrideVariance {} .module overridevariance.exe .class public A extends [mscorlib]System.Object { .method public specialname rtspecialname instance void .ctor() cil managed { .maxstack 1 ldarg.0 call instance void [mscorlib]System.Object::.ctor() ret } .method public newslot virtual instance object Method() cil managed { .maxstack 1 // return new object(); newobj instance void [mscorlib]System.Object::.ctor() ret } } .class public B extends A { .method public specialname rtspecialname instance void .ctor() cil managed { .maxstack 1 ldarg.0 call instance void A::.ctor() ret } // explicit override of A.Method() .method private virtual instance object A.Method() cil managed { .override A::Method .maxstack 1 ldarg.0 callvirt instance class [mscorlib]System.IComparable B::Method() ret } .method public instance class [mscorlib]System.IComparable Method() cil managed { .maxstack 1 // int32 implements IComparable ldc.i4.1 box int32 ret } } .class public C extends B { .method public specialname rtspecialname instance void .ctor() cil managed { .maxstack 1 ldarg.0 call instance void B::.ctor() ret } // explicit override of A.Method() .method private virtual instance object A.Method() cil managed { .override A::Method .maxstack 1 ldarg.0 callvirt instance string C::Method() ret } .method public instance string Method() cil managed { .maxstack 1 ldsfld string [mscorlib]System.String::Empty ret } } .class public Program extends [mscorlib]System.Object { .method private static void Main() cil managed { .entrypoint // call A.Method() on an instance of A ldstr "Calling A.Method on A: " call void [mscorlib]System.Console::Write(string) newobj instance void A::.ctor() callvirt instance object A::Method() call void Program::Output(object) // call B.Method() on an instance of B ldstr "Calling B.Method on B: " call void [mscorlib]System.Console::Write(string) newobj instance void B::.ctor() callvirt instance class [mscorlib]System.IComparable B::Method() call void Program::Output(object) // call C.Method() on an instance of C ldstr "Calling C.Method on C: " call void [mscorlib]System.Console::Write(string) newobj instance void C::.ctor() callvirt instance string C::Method() call void Program::Output(object) // call A.Method() on an instance of B ldstr "Calling A.Method on B: " call void [mscorlib]System.Console::Write(string) newobj instance void B::.ctor() castclass A callvirt instance object A::Method() call void Program::Output(object) // call A.Method() on an instance of C ldstr "Calling A.Method on C: " call void [mscorlib]System.Console::Write(string) newobj instance void C::.ctor() castclass A callvirt instance object A::Method() call void Program::Output(object) // call B.Method() on an instance of C ldstr "Calling B.Method on C: " call void [mscorlib]System.Console::Write(string) newobj instance void C::.ctor() castclass B callvirt instance class [mscorlib]System.IComparable B::Method() call void Program::Output(object) ret } .method private static void Output(object obj) cil managed { .maxstack 1 // Console.WriteLine(obj.GetType().ToString()); ldarg.0 callvirt instance class [mscorlib]System.Type [mscorlib]System.Object::GetType() callvirt instance string [mscorlib]System.Object::ToString() call void [mscorlib]System.Console::WriteLine(string) ret } }