internal class SchoolCalendar
{
public void GetSchoolYear()
{
Console.WriteLine("Base GetSchoolYear called from: " + this);
LeapYear();
}
public virtual void LeapYear()
{
Console.WriteLine("Base Leap Year");
}
}
internal class DerivedSchoolCalendar : SchoolCalendar
{
public override void LeapYear()
{
Console.WriteLine("Derived Leap Year");
}
}
internal class Program
{
static void Main(string[] args)
{
SchoolCalendar bsy = new DerivedSchoolCalendar();
bsy.GetSchoolYear();
}
}
In the code above, the base class calls a base class method, and said method calls a virtual method.
I'm trying to figure out in more detail how a vtable works. Especially the order of things. I was taught that in this code the vtable for the derived class is invoked. I thought that the vtable for the base class was invoked first and only then a pointer to a second vtable is invoked.
I would like to know more and better about order of it's workings inside whatever vtable. Is there a way to debug having a mind I just want to follow vtable access? (note, I know nothing about reflection for example, be gentle please).
User @HansPassant placed a comment which I consider to be the answer. The SOS extension for WinDbg in combination with the dumpmt command will provide data to figure out my own question.