










class A
{
static A()
{
X=B.Y+1; ---------------third
}
public static int X=0; ---------------second
}
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);
}
}
结果为 1,2
执行顺序为:先执行入口函数所在类的静态属性!,然后执行静态构造器.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。