C #=& amp; gt; virtual Method

Source: Internet
Author: User

1. If the keyword is virtual, a base class function can be declared as a virtual method. Public virtualvoid myVirtualMethod (){}

2. You can also declare the attribute as virtual.

Public virtual int iCount {get; set ;}

3. The virtual function can be rewritten in a derived class. Use the keyword override.

4. All functions in java are virtual, but C # is different. Except constructors, functions in C # Are not virtual by default, in addition, C # requires that the override keyword must be used to display the declaration when the function of the derived class is rewritten.

5. The advantage of override display Declaration is that C ++ ignores this problem if the method name of the derived class is slightly different from the base class, however, a compilation error occurs in C # because the function is marked as override.

Related Article

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.