C # Basic-method override (new) and overwrite (override)

Source: Internet
Author: User

Recently we have seen the basics.

There is a little bit of understanding when you see the rewrite (new) and overwrite (override) method.

So Baidu's.

The answer .....

Either the overwrite (override) and the overload (Overlord) are confused.

Either the rewrite (new) and overwrite (override) are reversed.

Last resort to Google.

See a better answer in StackOverflow:

--------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------

Virtual: Indicates that a function is overriden by an inheritor

override: Overrides the functionality of a virtual function in a base class, providing different functionality.

New: hides the original function (which doesn ' t has to be virtual), providing different functionality. This should only being used where it is absolutely necessary.

When you hide a method, you can still access the original method by up casting to the base class. This was useful in some scenarios, but dangerous.

--------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------

The translation is (please correct me in the wrong place, TKS):

Override (Overwrite):

Virtual: Indicates that this method may be overridden by the successor (Child method) (override)

Override: Override virtual methods in base class to provide different implementation methods

New (Override):

Hides the original method (not necessarily the virtual method), providing a different implementation method. This (rewrite) should be used only where it is necessary (that is, it is not recommended in general places).

When you hide a method, you can still access the original method by pointing to the base class. This is useful in some scenarios, but more dangerous.

--------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------

So

Override is generally an extension of the original virtual method , and the original method must be prefixed with the virtual modifier.

New is generally used to extend the original non- virtual method, but it is not recommended.

Personal understanding, if not right, generous enlighten!

C # Basic-method override (new) and overwrite (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.