Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 简单继承问题_C#_Inheritance - Fatal编程技术网

C# 简单继承问题

C# 简单继承问题,c#,inheritance,C#,Inheritance,我听到一些错误,如: “名称“title”在其当前上下文中不存在” “名称‘author’在其当前上下文中不存在” “名称“流派”在其当前上下文中不存在” “名称“pages”在其当前上下文中不存在” 我错过了什么?提前感谢。您还必须将成员变量传递给派生类,然后使用这些变量初始化基类 在您的书籍的构造函数中,您希望它使用的标题、作者、类型和页面的值是什么?您希望将它们传递给构造函数吗?如果是这样,则需要修改书本构造函数,使其如下所示: public Book(string title, stri

我听到一些错误,如:

“名称“title”在其当前上下文中不存在” “名称‘author’在其当前上下文中不存在” “名称“流派”在其当前上下文中不存在” “名称“pages”在其当前上下文中不存在”


我错过了什么?提前感谢。

您还必须将成员变量传递给派生类,然后使用这些变量初始化基类

在您的
书籍的构造函数中,您希望它使用的标题、作者、类型和页面的值是什么?您希望将它们传递给构造函数吗?如果是这样,则需要修改书本构造函数,使其如下所示:

public Book(string title, string author, string genre, int pages, bool hardcover)
    : base(title, author, genre, pages)
{
    Hardcover = hardcover;
}
public Book(string title, string author, string genre, int pages, bool hardcover)
    : base(title, author, genre, pages)
{
    Hardcover = hardcover;
}