【发布时间】:2012-02-04 13:05:08
【问题描述】:
为什么 var b = new B() 首先进入 static B() .ctor 而不是 static A() .ctor 而不是像实例构造函数那样反之(@ 987654326@ 和 public B())?
public class A
{
static A() {}
public A() {}
}
public class B : A
{
static B() {}
public B() {}
}
【问题讨论】:
-
这个和Why aren't all static constructors called in C#基本一样,答案基本一样:静态构造函数不被继承。
标签: c# .net c#-4.0 constructor static-constructor