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 8861543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:30:54+00:00 2026-06-14T15:30:54+00:00

I am having trouble with a homework assignment, were we are supposed to make

  • 0

I am having trouble with a homework assignment, were we are supposed to make a phonebook. The condition is that it is supposed to look like this:

Class Phonebook   
{
    private List<Entry> _phoneList;
    public Phonebook()
    {
       //instance of _phoneList
    }
    public void AddEntry (string name, string number)
    {
       //logic
    }
    public string FindEntry (string namne)
    {
       //logic
    }
}

class Entry
{
  public string Name{ get; private set; }
  public string Number{ get; private set; }
}

However, I am not certain in how to make the AddEntry method assign new names/numbers to Entry list _phoneList. I have tried a lot, but to no avail. Any hints how to make it work? Any help would be much appreciated!

My code thus far looks like this

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace app3
{
    public partial class Form1 : Form
    {
        private Phonebook phonebook;
        public Form1()
        {
            InitializeComponent();
            phonebook = new Phonebook();
        }
            private void addEntryButton_Click(object sender, EventArgs e)
        {
            phonebook.AddEntry((addNameTextBox.Text), (addNumberTextBox.Text));
        } 
    } 
    class Phonebook
    {
        private List<Entry> _phoneList;
        public Phonebook()
        {  
            List<Entry> _phoneList = new List<Entry>(); 
        }
        public void AddEntry(string name, string number)
        {
        }
    }
    class Entry
    {
        public string Name { get; private set; }
        public string Number { get; private set; }
    }
}
  • 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-06-14T15:30:55+00:00Added an answer on June 14, 2026 at 3:30 pm

    Since _phoneList is a collection of Entry‘s, you need to create a new instance and add it to the list.

    Entry entry = new Entry();
    entry.Name = name;
    entry.Number = number;
    _phoneList.Add(entry);
    

    However since Entry has private setters for the properties, you should add a new constructor taking in the name and number and set it there instead.

    class Entry
    {
        public Entry(string name, string number)
        {
           Name = name;
           Number = number;
        }
    
        public string Name { get; private set; }
        public string Number { get; private set; }
    }
    

    and then it would simply become

    _phoneList.Add(new Entry(name, number));
    

    Edit:

    private List<Entry> _phoneList;
    public Phonebook()
    {  
      List<Entry> _phoneList = new List<Entry>(); 
    }
    

    You declare _phoneList as a private field, but then you re-declare it in your constructor which hides the original.

    When you later use _phoneList in your AddEntry method, you’re getting the uninitialized field. Change the constructor to

    _phoneList = new List<Entry>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a homework assignment and I'm having trouble with my output. Everything works
I am having trouble with a homework question that I've been working at for
First off this is for homework or... project. I'm having trouble understanding the idea
I am having trouble correctly modeling related objects that can use templates. This is
This is for class homework. She is making us use array and array list
This is a homework problem that I am having difficulty with. The skeleton for
This is for a homework assignment. I am supposed to change the contents of
This is homework but the lesson gives me the answer already. I'm having trouble
I am having trouble with this assignment because my of my actionlisteners. Right now
I'm having some trouble writing Pseduocode for a homework assignment in my operating systems

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.