我目前正在尝试制作 HighScore 课程,但不确定如何正确完成。这是到目前为止的代码:
class HSItem
{
private string name;
private int points;
//Constructor Method
public HSItem(string name, int points)
{
this.name = name;
this.points = points;
}
//Property for name
public string Name
{
get { return name; }
set { name = value; }
}
//Property for points
public int Points
{
get { return points; }
set { points = value; }
}
}
二等:
public class HighScore
{
//Method HighScore constructor for list cap
public HighScore(int maxInList)
{
List<int> topHS = new List<int>(maxInList);
}
//Method for Add
public void Add(string name, int points)
{
List<HSItem> hs = new List<HSItem>();
hs.Add(new HSItem { Name = name, Points = points });
}
}
但是我得到了这个错误'HighScore.HSItem' does not contain a constructor that takes 0 arguments
,这让我一无所知。
构造Highscore
函数是接受一个数字来确定列表可以拥有的最大空间,Add()
方法是向第一个类添加新信息。
我很感激帮助