我对什么是默认构造函数访问修饰符以及这个 MSDN statemtn 说了什么感到困惑
If the direct base class does not have an accessible parameterless instance constructor, a compile-time error occurs.
因为当我用测试程序应用它时它失败了。我可以创建一个继承另一个类的对象或类,尽管没有定义外部无参数构造函数。
class A
{
}
class B : A
{
}
class C
{
public void main()
{
B objB = new B();// as per MSDN here should be the compile time error.
}
}
[ Source ]
最佳答案
If the direct base class does not have an accessible parameterless instance constructor, a compile-time error occurs.
如果类的构造函数未定义,编译器将自动生成一个公共(public)默认构造函数。
关于c# - 什么是默认的构造函数访问修饰符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22092140/