Reputation: 451
I have two class.One class inherits from another. Also I use polymorphism with virtual function. Can I see the table of virtual function? I want to understand the mechanism of virtual functions.
public class A
{
public virtual void foo()
{
}
}
public class B:A
{
public override void foo()
{
}
}
...
A a=new B();
a.SomeMethod();//show table of virtual function
Upvotes: 1
Views: 459
Reputation: 56
it's not possible to actually see the virtual table since the CLR polymorphism mechanism isn't based on a pointer allocated for each instance that points to a virtual table like you probably familiar with from C++ language.
.NET keeps a pointer to a type object for each instance, which respectively points to a method table that manages the actual implementation to be called.
Look here for more details.
Upvotes: 2