1、静态构造函数和实例构造函数可共存:前者为类加载时执行,后者为new时执行
2、静态构造函数无参数,且访问修饰符存在与否没意义:由.NET运行库调用
3、静态构造函数使用的原因:在第一次使用类时,从外部源中初始化某些静态字段方法
4、静态构造函数的执行:.NET运行库不能确保其执行时间,但必定是在代码引用类前执行,且仅仅只一次
class A
{
static A()
{
X=B.Y+1; ---------------third
}
public static int X=0; ---------------second
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
class B
{
static B(){} -------------------fourth
public static int Y=A.X+1; -------------------first
static void Main()
{
Console.WriteLine("X={0}" ,A.X);
Console.WriteLine("y={0} ", B.Y);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
}
2、静态构造函数无参数,且访问修饰符存在与否没意义:由.NET运行库调用
3、静态构造函数使用的原因:在第一次使用类时,从外部源中初始化某些静态字段方法
4、静态构造函数的执行:.NET运行库不能确保其执行时间,但必定是在代码引用类前执行,且仅仅只一次
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
结果为 1,2
执行顺序为:先执行入口函数所在类的静态属性!,然后执行静态构造器.