Readonly static field initialization order

I'm curious that the C # specification talks about the initialization order of a static field in C # 5 (.net4). For instance:

public class Test
{
   public static readonly string A = "hi";
   public static readonly string B = "bye";
   public static readonly string DEFAULT = A;
}

When tested (Mono 2.x), they seem to be initialized in the order they appear in the code. eg. As it is, it DEFAULTwill have the meaning "hi", but if I translate the definition for DEFAULTA and B above, it will be assigned NULL, since A has not been assigned yet.

Is there any guarantee that the variables are initialized in order? Or does it depend on the compiler?

Thank.

+4
source share
1 answer

In the order of their appearance. See here .

, .

, :

( 10.11) . .

+7

All Articles