Define the following test class public class Test{public static int msA = 10;static Test () {System.Console.WriteLine (string. Format ("msa0:{0}", MSA); MSA = MSA + MSA; System.Console.WriteLine (String. Format ("msa1:{0}", MsA);} public Test () {MsA = 30; System.Console.WriteLine (String. Format ("msa2:{0}", MsA);} public static int Geta () {System.Console.WriteLine (string. Format ("msa5:{0}", MSA); return MSA;}} public class Testchild:test{public static int msA = 40;} Execute the following code in the main function System.Console.WriteLine ("Test begin"); System.Console.WriteLine (String. Format ("msa6:{0}", Testchild.msa)); System.Console.WriteLine (String. Format ("msa3:{0}", Test.geta ())); System.Console.WriteLine (String. Format ("msa3:{0}", Test.msa)); Test obj1 = new test (); System.Console.WriteLine (String. Format ("msa4:{0}", Test.msa)); System.Console.WriteLine (String. Format ("msa6:{0}", Testchild.msa)); the output is as follows Test BEGINMSA6:40MSA0:10MSA1:20MSA5:20MSA3:20MSA2:30MSA4:30MSA6 : 40 Conclusion: (1) A static constructor is called before the first instantiation or referencing any static member (variable or method) and cannot be called directly. (2) The static constructor is executed only once. (3) Static constructors do not allow access to repairDecoration and parameters, or compile an error. (4) A static constructor is not inherited, that is, the child class will not be called until the first instantiation or reference to any static member (variable or method) is a static constructor of the parent class. (5) Static constructors are allowed to not be defined and can coexist with parameterless constructors. (6) Static constructors are thread-safe. This article references and references the following picture http://blog.csdn.net/xxdddail/article/details/38058121
cs--Static constructor