O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How Base Calls Work

Now that you know how virtual calls are made, one remaining question is how a base call avoids getting trapped in some kind of endless recursion. Consider the following code we wrote for Student:

class Student : Person{    public override string ToString()    {        return base.ToString() + " and attends " + College;    }}

Assume the base call for ToString would be handled in a virtual manner using a callvirt instruction for System.Object::ToString. The innards of virtual dispatch would inspect the vtable of the runtime type of the object (that is, a Student). In the slot for ToString, a reference would be found to the Student’s ToString code, as shown in the preceding code. So, we end up where ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required