简单的继承问题

Str*_*gos 0 c# inheritance

我收到一些错误说:

"名称'title'在其当前上下文中不存在""名称'author'在其当前上下文中不存在""名称'genre'在其当前上下文中不存在""名称'pages'不存在存在于它的当前背景中"

using System;
using System.Collections.Generic;
using System.Text;

namespace ReadingMaterials
{
    class Program
    {
        static void Main(string[] args)
        {

        }

        public class Basic
        {
            protected string Title;
            protected string Author;
            protected string Genre;
            protected int Pages;

            public Basic(string title, string author, string genre, int pages)
            {
                Title = title;
                Author = author;
                Pages = pages;
                Genre = genre;
            }

            public int PageCount
            {
                get { return Pages; }
                set { Pages = value; }
            }

            public string GenreType
            {
                get { return Genre; }
                set { Genre = value; }
            }

            public string AuthorType
            {
                get { return Author; }
                set { Author = value; }
            }

            public string TitleName
            {
                get { return Title; }
                set { Title = value; }
            }
        }

        public class Book : Basic
        {
            protected bool Hardcover;

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

            public bool IsHardcover
            {
                get { return Hardcover; }
                set { Hardcover = value; }
            }
        }


    }
}
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么?提前致谢.

Dea*_*ing 13

在你的构造函数中Book,你期望它使用什么值的标题,作者,流派和页面?你期望它们被传递给构造函数吗?如果是这样,您需要将Book构造函数修改为如下所示:

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