当我尝试从另一个类的列表中访问项目时,我收到错误:
指数超出范围。必须是非负数且小于集合的大小。参数名称:索引
我是否也需要在另一个(或相同的)列表中设置访问器,还是我的代码有问题?
WordList.cs 已
更新
private List<string> words = new List<string>();
private List<string> anagrams = new List<string>();
public void addword(string word)
{
Words.Add(word);
Anagrams.Add(anagram(word)); //Note: 'anagram' is a (public) String which makes an anagram of the word, and returns it
}
public List<string> Words
{
get
{ return words; }
}
public List<string> Anagrams
{
get
{ return anagrams; }
}
game.cs 更新
public void newword()
{
WordList list = new WordList();
Random rnd = new Random();
int num = rnd.Next(0, WordList.Anagrams.Count);
info.Text = "The anagram is " + list.Anagrams[num] + " guess the original word";
}
注意:我仍然得到同样的错误