静态类相关
静态类调用其静态的方法的时候,如果该静态类拥有无参构造,优先调用。
代码段:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
static void Main() { SimpleTest.ShowMsg(); Console.ReadLine(); } public static class SimpleTest { static SimpleTest() { Console.WriteLine("SimpleTest()"); } public static void ShowMsg() { Console.WriteLine("ShowMsg"); } }
运行结果: