C#C
C#3y ago
6 replies
Dinny

✅ Reading matricies to an output file

I am trying to read the data inside two matricies from an input file firstly in order to add them together and display the result to the output file. Before I get to that, I am struggling trying to get the program to read each row and column. Here's the block of code with my errors

 //going through each row to get matrix numbers
 while (!reader.EndOfStream)
 {

     nextLine = reader.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
     if (nextLine.Length == numOfColumns)
     {
         for (int j = 0; j < numOfColumns; j++)
         {

             a[rowIndex, j] = int.Parse(nextLine[j]);

         }

         rowIndex++;


     }
 }

I have a red line where it says " a[rowIndex, j] = int.Parse(nextLine[j]); and the error reads "Cannot apply indexing [] to an expression of type "Matrix.Matricies."
Was this page helpful?