string[] words;
numOfMatrix = int.Parse(fileIn.ReadLine());
nameOfMatrix1 = fileIn.ReadLine();
words = fileIn.ReadLine().Split(' ');
matrix1H = int.Parse(words[0]);
matrix1W = int.Parse(words[1]);
matrix1 = new int[matrix1H + 1, matrix1W + 1];
for (int i = 1; i <= matrix1H; i++)
{
int k = 0;
words = fileIn.ReadLine().Split(' ');
for (int j = 1; j <= matrix1W; j++)
{
matrix1[i,j] = int.Parse(words[k]);
k++;
}
}
Input Sample Data
3
Matrix One
5 7
45 38 5 56 18 34 4
87 56 23 41 75 87 97
45 97 86 7 6 8 85
67 6 79 65 41 37 4
7 76 57 68 8 78 2
Matrix Two
6 8
45 38 5 56 18 34 4 30
87 56 23 41 75 87 97 49
45 97 86 7 6 8 85 77
67 6 79 65 41 37 4 53
7 76 57 68 8 78 2 14
21 18 46 99 17 3 11 73
Matrix Three
6 6
45 38 5 56 18 34
87 56 23 41 75 87
45 97 86 7 6 8
67 6 79 65 41 37
7 76 57 68 8 78
21 18 46 99 17 3
Unhandled Exception: System.FormatException: Input string was not in a correct format. at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.Int32.Parse(String s)
On the line where I parse words[k] into matrix1[i,j] I get an error message. Parse works fine the first time I use words[] but not the second time I read something in.
indexOutOfBoundserror on your first line3when you read that line and then try to setmatrix1Wtowords[1]