For some reason, I've failed to find documentation on this. It looks like, in C#, the const fields of a class are initialized before static fields, as it can be seen from this code:
class Program {
static int p = f;
const int f = 10;
static void Main(string[] args){
System.Console.WriteLine("{0}", p);
System.Console.ReadLine();
}
}
(this outputs 10
, while if I replace const
with static
, it outputs 0
).
The question is: Is such behaviour always the case? Also, what is, generally, the order of initialization of different kinds of static class fields?