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()
{
Console.WriteLine("X={0},Y={1}", A.X, B.Y);
}
}
Implementation process:
- Because there is a main function in class B, first initialize class B,
- Y=A.x+1; Ax is referenced, and the compiler initializes Class A
- The member variable x of class A, ——> the constructor A(), B is not initialized at this time, so By is 0, so Ax=1;
- Return to ClassB, continue to initialize the member variable Y, the value is 2.
Results of the