我不明白为什么我会收到此错误,因为我的多维数组应该可以正常运行但由于列出的错误而无法在这种情况下工作......我非常沮丧。
错误是:Wrong number of indices inside []; expected 2
这就是我所拥有的:
public static void DisplayTopScore(string username, double score)
{
string[] highscores = System.IO.File.ReadAllLines(@"C:\Users\Public\TestFolder\WriteLines2.txt");
string[,] Temphighscores = new string[10, 2];
string[] TempScoresToSplit;
int counter=0;
foreach (string highScore in highscores)
{
TempScoresToSplit = highScore.Split(' ');
Temphighscores[counter][0]= TempScoresToSplit[0];
Temphighscores[counter][1]= TempScoresToSplit[1];
counter++;
}
}
}
指出错误索引数的地方是这两行:
Temphighscores[counter][0]= TempScoresToSplit[0];
Temphighscores[counter][1]= TempScoresToSplit[1];
答案 0 :(得分:8)
尝试:
Temphighscores[counter, 0] = TempScoresToSplit[1];
Temphighscores[counter, 1] = TempScoresToSplit[1];
代替。