相关疑难解决方法(0)

C#错误:Parent不包含带0参数的构造函数

我的代码是

public class Parent
{

    public Parent(int i)
    {
        Console.WriteLine("parent");
    }
}

public class Child : Parent
{
    public Child(int i)
    {
        Console.WriteLine("child");
    }

}
Run Code Online (Sandbox Code Playgroud)

我收到错误:

Parent不包含带0参数的构造函数.

我理解问题是Parent没有带0参数的构造函数.但我的问题是,为什么我们需要一个零参数的构造函数?没有它,为什么代码不工作?

c# inheritance constructor compiler-errors

141
推荐指数
4
解决办法
10万
查看次数

标签 统计

c# ×1

compiler-errors ×1

constructor ×1

inheritance ×1