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.