静态类不是不需要构造函数,而是不能定义普通的构造函数。
但是静态类可以定义静态构造函数。
“Static classes are sealed and therefore cannot be inherited. They cannot inherit from any class except Object. Static classes cannot contain an instance constructor; however, they can have a static constructor. For more information, see Static Constructors (C# Programming Guide). ”这是MSDN的官方说明。
举例:
static StaticClassSample {
static int Count = 0;
//public StaticClassSample () {} wrong
static StaticClassSample () {
Count = 0;
}
}
静态类不需要构造函数。直接调用就行了。
静态类不需要构造函数
静态类应该是不需要构造函数的吧