我有麻煩做家庭作業,我們是否應該製作電話簿。條件是,它應該是這個樣子:電話簿 - 進入班級列表
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
方法分配新的名稱/號碼條目列表_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; }
}
}
的功課標籤已經過時了。請刪除 –