Answer the question
In order to leave comments, you need to log in
.NET: Type Objects
As you know, during the execution of the program, the CLR creates objects-types in memory that contain, incl. method table.
Suppose there are two classes: Employee and Manager (child of Employee). When an instance of the Manager type is created, the type object reference points to the Manager type object. When a method is called on a Manager instance, an entry about this method is first looked up first in the method table of the Manager object-type, then Employee. However, Richter's book says that all type objects refer to the base Type object.
Then how is the relationship of types in the inheritance chain? I thought that the Manager type object would refer to Employee, and Employee in turn would refer to Type. Or is another mechanism at work here?
Answer the question
In order to leave comments, you need to log in
I can be wrong with the terms, but the principle of operation is approximately the following. There is such a thing as a "virtual table". If the method is "virtual" (available for overriding), then it is entered in this table. Then, when you override this method in the "heir" class, the new address is entered into this table. And even if you use a reference to a base type, but in fact there is an heir of this base type, the method of the heir will be called, thanks to this table
I find it difficult to give an answer, but it became interesting - in connection with what such a question arose?
Type object is not Type by any chance? It has nothing to do with the method table, it represents metadata.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question