【发布时间】:2013-12-02 07:28:01
【问题描述】:
我对 C# 还很陌生,而且我刚刚学会了创建自定义类。问题是,我无法弄清楚如何获取此类的 40~65 实例并将它们放入一个列表/数组(无论我需要哪个)中,我可以在其中找到并选择 one 基于其中定义的属性。
这是我现在创建的课程:
public class Team
{
protected int teamNum;
protected double averageMatchPoints;
protected string location;
protected int matchesPlayed;
protected int matchesPending;
protected int blowouts;
//Team Number
public void SetNumber(int num)
{
teamNum = num;
}
public int GetNumber()
{
return teamNum;
}
//Average Points per match
public void AverageMatchPoints(double p)
{
averageMatchPoints = p;
}
public double GetAverageMatchPoints()
{
return averageMatchPoints;
}
//location information
public void SetLocation(string l)
{
location = l;
}
public string GetLocation()
{
return location;
}
//Number of Played Matches
public void PlayedMatches(int mat)
{
matchesPlayed = mat;
}
public int GetPlayedMatches()
{
return matchesPlayed;
}
//Number of matches pending (not played)
public void PendingMatches(int pen)
{
matchesPending = pen;
}
public int GetPendingMatches()
{
return matchesPending;
}
//Number of Blowouts (matches where the robot was disbaled for any number of reasons)
public void SetBlowouts(int b)
{
blowouts = b;
}
public int GetBlowouts()
{
return blowouts;
}
}
现在,如果我有 40~65 支这样的球队参加比赛,并且我为每个球队创建了一个此类的实例,我将如何用每个 球队编号填充组合框 (teamNum),然后通过他们的团队编号在程序中的所有实例中找到一个特定的团队?
【问题讨论】:
-
您使用的是 Windows 窗体吗?此外,当您将团队添加到组合框时,您是尝试通过用户选择来定位项目还是要通过代码定位项目?除了团队编号之外,组合中还会出现什么?
标签: c# arrays list class search