我在做家庭作业时遇到了麻烦,我们应该制作电话簿吗?条件是它应该看起来像这样:
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; }
}
但是,我不确定如何使该AddEntry
方法为 Entry list 分配新的名称/编号_phoneList
。我已经尝试了很多,但无济于事。任何提示如何使它工作?任何帮助将非常感激!
到目前为止,我的代码看起来像这样
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; }
}
}