RokasM RokasM - 4 months ago 27
C# Question

Index was outside the bounds of the array error. C#

I am trying to create a two dimensional numeric array in c#. In which there are the following simple methods: generates the array, shows the array results in the console and finally counts and shows the sum of all of the rows and columns in it.

But when i am trying to get the sums of rows and columns i get this error:

The Error

The number of rows and columns are specified in the first row of the data.txt file.(5 rows and 7 columns)

The data.txt file looks like this:

Data file

This is my first post in SOF so i apologize for any mistakes.

thanks in advance.


Assuming column count != row count - it should be

result = new int[columns] instead of result = new int[rows]

since you initialize result with result = new int[rows] and i is iterating the columns