C # static Constructor

Source: Internet
Author: User

Class GoodClass

{

Static GoodClass ()

{

}

}

This is a static constructor. Unlike the common constructor, it belongs to this class. It will only be instantiated once. This method is not called after the object is instantiated.

Execute this constructor before instantiating or calling any static method, which is called by. net!

Note the following points:

1. Static constructor. There is no modifier such as public, because it is called by. NET itself.

2. When the class is instantiated or any static method is called, it is automatically called and cannot be controlled by ourselves.

3. Only one static constructor can be created.

4. It can be used together with a common constructor. A common constructor belongs to an instance and a static constructor belongs to a class.

5. You can only run it once at most.

6. Static constructor cannot be inherited

7. If the static constructor method is not declared, but the class contains static methods or static attributes, the compiler automatically creates a static method for the class.

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.