Earlier in the emit learning process, many times encountered the call to the method, found that sometimes use calls and sometimes the use of callvirt, has been not very understanding of the difference between the two. The MSDN is then reviewed and the explanations for both are as follows:
L Call: Invokes the method indicated by the passed method descriptor;
L Callvirt: Calls the late-bound method on an object and pushes the return value onto the evaluation stack.
But after reading it is still very do not understand, I think it may be because of the Chinese version of it. This afternoon again saw the interpretation of the callvirt instructions, "to object call late binding method", suddenly thought, this seems to refer to the meaning of polymorphism? In a look at Virt, should be the abbreviation of virtual, so more sure of their own ideas (in the Agricultural Bank, not online, or in the garden to find a result, sad ah!) ), and immediately began to practice.
We use the classic animal example to validate this idea by first defining the relevant type, as follows:
Animal
Class Animal
{public
virtual void Speak ()
{
Console.WriteLine ("Animal.speak");
}
class Cat:animal
{public
override void Speak ()
{
Console.WriteLine ("Cat.s Peak ");
}
class Dog:animal
{public
override void Speak ()
{
Console.WriteLine ("D og. Speak ");
}
}