c# - 什么是默认的构造函数访问修饰符?

标签 c#

我对什么是默认构造函数访问修饰符以及这个 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/

相关文章:

c# - WebClient 抛出 SocketException(无效参数)

c# - 如何在 C# 中读取 adsense URL(鼠标悬停时显示的 URL)

c# - 如何解析文本文件c#并获得正确的结果数据

c# - 模拟不起作用时如何让我的单元测试保持干燥?

c# - 将 C# 语句体 lambda 转换为 VB

c# - 在 C# 中,如何将两个参数个数和类型不同的方法转换为一个方法?

c# - 为什么 String.Equals 返回 false?

C# WPF Modern UI 禁用或隐藏 LinkGroup

c# - 查找 IEnumerable 的第一个索引

c# - 在 foreach 中继续