问题
In what order are the static constructors of parent and child classes called?
class A { static A() { MessageBox.Show("Yaht"); } }
class B : A { static B() { MessageBox.Show("Zee"); } }
class C : A { static C() { MessageBox.Show("Zey"); } }
static void Main()
{
B b = new B();
C c = new C();
}
I could test it right now... if I had a compiler available.
回答1:
Output:
Zee
Yaht
Zey
..........
来源:https://stackoverflow.com/questions/5240011/in-what-order-are-the-static-constructors-of-parent-and-child-classes-called