I have 2 classes associated with one and other, a Town has many People in it.
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"));
}
}
After constructing an instance of a Town in a List, and a record associated with it I'd like to display the result on a Form.
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;
}
How would I reference a List inside a List, to display or count the number of records within it (town0 .. show people1, 2, 3 etc)?