我正在尝试了解 C# 中集合的用法,并练习如何根据 msdn 示例中给出的语句定义类,因为它的类没有发布并留给读者。我想出了以下课程,但需要知道这是对还是错:
声明说:
// ListLeagueList is a list of League objects.
// Each League object has a Name and a collection of Division objects.
// Each Division has a Name and a collection of Team objects,
// and each Team object has a Name.
public class Team
{
private string teamName;
public string TeamName
{
get { return teamName; }
set { teamName = value; }
}
}
public class Division
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
public List<Team> DivisionList;
}
public class League
{
private string Name;
public string name
{
get { return name; }
set { name = value; }
}
List<Division> DivisionList;
}
谢谢。