I can not sleep until I know how occur recalling the desired virtual method by C#/CLR. In my book richter wrote no more no less than what CLR determine the actual type of the object and call the appropriate method. For example, in C + +, each instance of the polymorphic class stores a pointer to a virtual table. But in C# instead of a pointer to virtual table with instance data stored some SyncBlk Index and TypeHandle. Do not understand how TypeHandle different from this pointer in C#. What is role of TypeHandle. For example in C++ we have
class A
{
int a;
public virtual void show() {}
};
class B: public A
{
int b;
public virtual void show() {}
};
How instance of A and B classes looks in memory, i write in peseudocode
A:
{
vtptr; // pointer to A vt
a;
}
B:
{
vtptr; // pointer to A vt + B vt
a;
b;
}
So then in C++ we run code
A* pa = new B();
pa->show();
It is clear that we creating B instance and cast him to A type, but we don't lose overridden address of show() and thank for that we can call B::show(). I really need to understand for a similar example of how C#/CLR performs casts to a base type and defines the virtual methods calls. Please help! I will be glad to know all technical details