I read the CLR through C # and I read the following:
Sometimes the compiler will use a call statement to invoke a virtual method instead of using the callvirt command. This may seem unexpected at first, but the code below shows why it is sometimes required:
internal class SomeClass {
public override String ToString() {
return base.ToString();
}
}
When calling base.ToString (virtual method), the C # compiler emits a call command to ensure that the ToString method in the base type is called non-virtual. This is necessary because if ToString is called practically, the call will be executed recursively until the stack thread is full, which is clearly not desirable.
Although this is explained here, I do not understand why the ToString actually called will execute recursively. Can someone give another explanation or describe it in a simpler way, if possible.
Thanks!
source
share