Static has to precede non-static - otherwise the non-static constructor could not rely on (or even access!) static elements of the class. So all static construction needs to precede all non-static.
Child construction must follow parent in non-static classes, so that child instances can rely on parent properties. In actual fact, the constructor for the child is called first - this triggers the parent constructor before any child code is executed.
The only one which looks odd is the child-first static, which is actually following the same order as the public: child constructor first, but the parent constructor is called the first time it is needed - so if you change your code slightly:
public class child : parent
{
public child()
{
Console.WriteLine("child ns");
}
static child()
{
Console.WriteLine("child s");
X = "goodbye";
Console.WriteLine("child s end");
}
}
public class parent
{
public static string X = "hello";
public parent()
{
Console.WriteLine("parent ns");
}
static parent()
{
Console.WriteLine("parent s");
}
You will get:
child s
parent s
child s end
parent ns
child ns
Because the parent static constructor is called when the child references a parent static property, or at the end of the child constructor if it hasn't been needed before then. Remember, Static constructors are called once, the first time a static property or method is referenced.
[edit]Typo: "public" instead of "parent" and a spare "the" - OriginalGriff[/edit]