C # constructor,

Source: Internet
Author: User

C # constructor,

Constructor is a special member function. It is mainly used to allocate storage space for objects and initialize data members.

Constructor has some special properties:

(1) The name of the constructor must be the same as that of the class;

(2) The constructor does not return a type. It can contain parameters or not;

(3) When declaring a class object, the system automatically calls the constructor. The constructor cannot be explicitly called;

(4) constructors can be overloaded to provide different methods for initializing class objects;

(5) If no constructor is defined during declaration, the system automatically generates the default constructor. The constructor body is empty.

(6) static constructor. static modifier is used to initialize static variables. A class only allows one constructor to be loaded during class instantiation. The modifiers public and private are ineffective.

(7) public, protected, and private modifiers can be used ..

(8) use the (): base () method when referencing the parent class constructor. Use (): this (int para) to reference its own overloaded constructor ).

(7) public, protected, and private modifiers can be used.

 

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.