在下面的代码中,如果我们使用常量字段,结果就可以了!但是当我们使用静态字段时,结果是不可预期的.
为什么和如何?
class Program
{
private static int x = y + 100;
private static int y = z - 10;
private static int z = 300;
public static void Main(string[] args)
{
System.Console.WriteLine("{0}/{1}/{2}",x,y,z); // 100/-10/300 why and how?
Console.ReadKey();
}
}
Run Code Online (Sandbox Code Playgroud)