• The static constructor has neither an access modifier nor a parameter.
• If a static constructor is not written and the class contains a static field with the initializer, the compiler automatically generates the default static constructor.
• When you create the first class instance or any static members are referenced. NET automatically invokes the static constructor to initialize the class, which means that we cannot call the static constructor directly, and we cannot control when the static constructor is executed.
• If the class contains the main method used to start execution, the static constructor for the class is executed before the main method is called.
• If a static field in a class is initialized, the initialization statement for the static field runs before the static constructor.
• A class can have only one static constructor.
• Parameterless constructors can coexist with static constructors. Although the argument list is the same, but one belongs to the class and one belongs to the instance, there is no conflict.
• Run at most once.
• Static constructors cannot be inherited.
• The sample code is as follows:
The results of the operation are:
Static A ()
Static B ()
x=1,y=2