Why var b = new B() firstly enters static B() .ctor and than static A() .ctor and not vice versa like the instance constructors does (public A() and than public B())?
public class A
{
static A() {}
public A() {}
}
public class B : A
{
static B() {}
public B() {}
}
Technically the instance constructor of
Bis entered first. But the first thing it does is calling the constructor ofAand only then goes to the user defined body.So I assume that directly before the constructor of
Bis entered the static constructor ofBneeds to run.Then the constructor of
Bcalls the constructor ofA, which triggers the static constructor ofA.