循环调用静态变量,你知道它的结果吗?

namespace CA_CycleInvokeStaticVariable
{
    using System;

    class A
    {
        public static int X;
        static A()
        {
            X = B.Y + 1;
        }
    }
    class B
    {
        public static int Y = A.X + 1;
        static B() { }
        static void Main(string[] args)
        {
            Console.WriteLine("X = {0}, Y = {1}", A.X, B.Y);
        }
    }
}
//X = 1, Y = 2

image

image

原文地址:https://www.cnblogs.com/volnet/p/1398216.html