C # Basic knowledge of the New keyword

Source: Internet
Author: User

    • Operator

New class, New completes two things: one is to call the new Class command to allocate memory for the instance in the managed heap, and the other is to call the constructor to implement the object initialization.

    • Modifier

Shows hidden members that inherit from the base class. Although you can hide members without the new modifier, a warning is generated. If a hidden member is displayed with the New keyword, this warning is canceled.

no new keyword code:

There is a new keyword code:

Results:

Note:

A method defined in a subclass with the same name as the parent class in the New keyword adornment is called overwrite. Overwriting does not change the functionality of the parent class method.

When a subclass creates a parent class, a c = new B () in the code overrides does not change the functionality of the parent class. The functionality of the parent class is still called.

    • New constraint

The new constraint means that any parameter type in a generic class declaration has a parameterless constructor, and when used with other constraints, the new constraint must be specified last.

 Public class   where class,new()    {    }

C # Basic knowledge of the New keyword

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.