为了加深我自己的理解,我正在复制一个简单的数据库 - 并且无法理解以下内容;
我有 2 个类城镇和人。一个城镇拥有许多 People 实例,并且设置如下;
public class Town
{
List<People> collectionOfPeople;
public string townName { get; set; }
public Town()
{
townName = "Cardiff";
collectionOfPeople = new List<People>();
collectionOfPeople.Add(new People("Daniel Smith"));
}
}
public class People
{
public string name { get; set; }
public People(string tmp_name)
{
name = tmp_name;
}
}
假设我所做的是正确的,Town 有 1 个值(卡迪夫),而 People 也有 1 个(Daniel Smith)或 .. Daniel 住在卡迪夫。
我正在尝试显示居住在镇内的人们的名字.. 以便以后循环浏览它们。(** = 我认为的问题)
private List<Town> townList;
private List<Town.People> peopleList; **
private void ShowData()
{
// Add to Text Box based on current Record
txt_town.Text = townList[0]).townName;
txt_name.Text = peopleList[0].name; **
}