tags:

views:

63

answers:

2

I get a few errors saying:

"The name 'title' does not exist in it's current context" "The name 'author' does not exist in it's current context" "The name 'genre' does not exist in it's current context" "The name 'pages' does not exist in it's current context"

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; }
            }
        }


    }
}

What am I missing here? Thanks in advance.

A: 

You will have to pass the member variables to the derived class as well and then use those to initialize the base class.

Brian R. Bondy
+12  A: 

In your constructor for Book, what values for title, author, genre and pages are you expecting it to use? Do you expect them to be passed in to the constructor? If so, you need to modify your Book constructor to look like this:

public Book(string title, string author, string genre, int pages, bool hardcover)
    : base(title, author, genre, pages)
{
    Hardcover = hardcover;
}
Dean Harding
Thank you sir! That worked =]
Stradigos