As I know, each variable knows about its runtime type.
Here is an example:
void Main()
{
C c = new C();
c.M();
I i = (I)c;
i.M();
}
public interface I
{
void M();
}
public class C : I
{
void I.M()
{
Console.WriteLine("I.M");
}
public void M()
{
Console.WriteLine("M");
}
}
If I understand it right, i
still knows that its type is C
. So, what is the mechanism which lets i
to decide on using I.M
instead of M
?
Internally each object has its own TypeHandle, see object internal structure below:
MSDN - Drill Into .NET Framework Internals to See How the CLR Creates Runtime Objects
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With