Emit learning-the difference between-call and callvirt in a question-answering article

Source: Internet
Author: User
Tags emit

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 ");

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.