I don't understand why I am getting this error because my multi-dimensional array should function fine but it isn't working in this case due to the listed error...I am very frustrated.
error is: Wrong number of indices inside []; expected 2
This is what I have:
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++;
}
}
}
The place where it says wrong number of indices are at these 2 lines:
Temphighscores[counter][0]= TempScoresToSplit[0];
Temphighscores[counter][1]= TempScoresToSplit[1];
Try:
Temphighscores[counter, 0] = TempScoresToSplit[1];
Temphighscores[counter, 1] = TempScoresToSplit[1];
instead.
The MSDN article on multidimensional arrays is probably worth a read.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With