2.2.5.4 Constructor
A constructor is a special method that calls it to initialize an object. The name of the constructor is always the same as the name of the class containing it and never returns a value. Constructor can be divided into the following two types:
1. The instance constructor is used to initialize a specific object instance.
2. Static constructor is also called before the first class.
Base class initialization
The constructor of the subclass calls the constructor of the base class. C # The Compiler inserts a call to the base class before executing any code in the constructor of the current class.
An overloaded constructor does not automatically search for base class constructor that matches the corresponding parameter list, but implicitly calls the default base class constructor.
Member Initial Value Setting
A value assignment expression is provided when a member variable is declared.
Static members can also be initialized as powerful members, but their initialization process should be performed before any force members are initialized. Correct initialization order:
1. Initialize all static fields.
2. Call the static constructor.
3. Change all instance fields.
4. Call the instance constructor.
Static Constructor
The static constructor is automatically called before the class instance is created.
2.2.5.5 destructor
Destructor is an optional member function, including the Code required to destroy an instance of the class.