我有 2 个与一个和另一个相关联的类,一个城镇中有很多人。
public class Town
{
List<People> collectionOfPeople;
public string town { get; set; }
public Town()
{
townName = "";
collectionOfPeople = new List<People>();
collectionOfPeople.Add(new People());
}
public Town(string tmp_townName)
{
townName = tmp_townName;
collectionOfPeople = new List<People>();
collectionOfPeople.Add(new People("Daniel Smith", "22"));
}
}
在列表中构造一个城镇的实例以及与之关联的记录后,我想在表单上显示结果。
private int numberOfPeople;
private int currentPeopleShown;
private int numberOfTown;
private int currentTown;
private List<People> peopleList;
private List<Town> townList;
// ************************* Methods/Functionality
private void LoadData()
{
txt_townName.Text = (townList[0]).townName;
txt_peopleName.Text = (peopleList[currentPeopleShown]).name;
numberOfPeople = peopleList.Count();
currentPeopleShown = 0;
}
我将如何引用列表中的列表,以显示或计算其中的记录数(town0 .. show people1、2、3 等)?