Static constructors are probably a bit unfamiliar to them, and static constructors are a new feature of C # that is not very useful in programming, and its main purpose is to initialize some static variables . You can refer to C # Getting Started Basics Tutorial.
1. Static constructors have neither access modifiers nor parameters. Because it is. NET calls, so modifiers like public and private are meaningless.
2, is when the first class instance is created or any static member is referenced. NET will automatically call 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.
3. A class can have only one static constructor.
4. Parameterless constructors can coexist with static constructors. Although the parameter list is the same, one belongs to the class and one belongs to the instance, so there is no conflict.
5, run up to one time only.
6. Static constructors cannot be inherited.
7. If a static constructor is not written, and the class contains a static member with an initial value set, the compiler automatically generates a default static constructor.
The default initial value of a global variable for a simple value type is 0 because the entry function is in class B, so the program first loads B, and because Y is a static member of B, the value of Y is computed when the class is loaded, but the value of Y is found to be obtained by assigning a value, and the value of x is immediately computed. X is initialized by the static constructor of Class A, and references the y of B, at which point y is still 0 (because the assignment statement of Y is not finished, so its value is the default), get x=0+1=1, continue to be worth to Y y=x+1=2.
For more programming language Tutorials , You can visit the E-mentor Web.
C # Programming Fundamentals: Static constructors