Possible Duplicate:
What is the static variable initialization order in C#?
For fun i ran this code
I was not expecting 2 2 3
. I was expecting a compiler error (circlur dependency) or 8 5 3
.
What are the rules to initialization order in C#?
-edit- i tried making a not static and i got what i expected. Why is b 2 before and now 5. I don't think i'm going to like the rules... Luckily i never do anything like this so i haven't had a problem.
using System;
public class Test
{
public static void Main()
{
A.t();
}
}
class A
{
static int a = B.b + c;
public static int c = 3;
static public void t()
{
Console.WriteLine("{0} {1} {2}", a, B.b, c);
}
}
class B
{
public static int b = A.c+2;
}