Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6559635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:21:14+00:00 2026-05-25T13:21:14+00:00

Here is yet another problem which I would like some explanation on. On line

  • 0

Here is yet another problem which I would like some explanation on. On line 47 I am getting errors saying:

Error CS0122: ‘PROPERTY NAMES’ is inaccessible due to its protection level (CS0122)

The question is why is there an error, and how can I avoid this? And if I’m doing this homework correctly. And if I should be calling properties or variables? My guess is for properties.

PS. Code isn’t finished yet.

NOTE! My professor gave us class diagram telling us what properties should be in place and which should have get/set and which just set.

Problem with code:

    public void display()
    {
        Console.Write("{0}\n{1}\n{2}\n{3}", Title, getAuthorName(), PublisherName, Price);
    }

Whole code:

using System;

namespace Lab_3
{
    class BookTest
    {
        static void Main(string[] args)
        {
            Book book1 = new Book();
            Book book2 = new Book("Advenced C#", "Joe", "Robertson", 29.99f, "PUC Press");
        }
    }

    public class Book
    {
        string authorFirstName;
        string authorLastName;
        float price;
        string publisherName;
        string title;

        public Book()
        {
            Console.Write("Enter book title: ");
            Title = Console.ReadLine();
            Console.Write("Enter author's first name: ");
            AuthorFirstName = Console.ReadLine();
            Console.Write("Enter author's last name: ");
            AuthorLastName = Console.ReadLine();
            Console.Write("Enter price: ");
            Price = float.Parse(Console.ReadLine());
            Console.Write("Enter publisher's name: ");
            PublisherName = Console.ReadLine();
        }

        public Book(string bookTitle, string firstName, string lastName, float bookPrice, string publisher)
        {
            authorFirstName = firstName;
            authorLastName = lastName;
            price = bookPrice;
            publisherName = publisher;
            title = bookTitle;
        }

        public void display()
        {
            Console.Write("{0}\n{1}\n{2}\n{3}", Title, getAuthorName, PublisherName, Price);
        }

        public string getAuthorName()
        {
            return AuthorFirstName + AuthorLastName;
        }

        public string AuthorFirstName
        {
            get
            {
                return authorFirstName;
            }
            set
            {
                authorFirstName = value;
            }
        }

        public string AuthorLastName
        {
            get
            {
                return authorLastName;
            }
            set
            {
                authorLastName = value;
            }
        }

        public float Price
        {
            set
            {
                price = value;
            }
        }

        public string PublisherName
        {
            set
            {
                publisherName = value;
            }
        }

        public string Title
        {
            set
            {
                title = value;
            }
        }

    }
}

EDIT: Solved! Thank you all for help.

In conclusion I CAN’T use properties because some are READ-ONLY which caused me problems. So I needed to use private variables to display them.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:21:14+00:00Added an answer on May 25, 2026 at 1:21 pm

    Since you’re in the class where the method display() is in don’ event bother using the Properties, just use the data members themselves since this is probably what your professor wanted. Properties are used to expose the data to users of your class. In your class you are free to use the data members without needed the getters or setters:

    Console.Write("{0}\n{1}\n{2}\n{3}", title, getAuthorName(), publisherName, price);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After getting a helpful answer here , I have run into yet another problem:
yet another PHP question which I am stuck on, so here is what im
Yet another SVN guideline question, I know. I recently joined a new company which
SQL queries are still my weakest point, so here I am with yet another
So here's yet another 'write a query to X' challenge. I'm monitoring a number
Yet another strange WPF error: I have a custom control in a simple XAML
Yet another problem whilst trying to create the UI for an app. I've got
First question here: it is a very short yet fundamental thing in Java that
Here is pseudo-code of how I setup an array representing the MandelBrot set, yet
So I'm not quite convinced about OpenID yet, and here is why: I already

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.