Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong number of indices inside, expected 2

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];
like image 724
user2838559 Avatar asked Dec 26 '22 19:12

user2838559


1 Answers

Try:

Temphighscores[counter, 0] = TempScoresToSplit[1];
Temphighscores[counter, 1] = TempScoresToSplit[1];

instead.

The MSDN article on multidimensional arrays is probably worth a read.

like image 199
Andrew Whitaker Avatar answered Dec 28 '22 10:12

Andrew Whitaker