-5

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:

enter image description here

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:

enter image description here

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

thanks in advance.

fubo
  • 44,811
  • 17
  • 103
  • 137
Morningas
  • 25
  • 7

1 Answers1

1

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

fubo
  • 44,811
  • 17
  • 103
  • 137
  • Up voted this answer. As array is initialized with rows and the loop is iterating on columns so the columns can be greater than row which causes the error. – Sahib Khan Nov 14 '16 at 15:26
  • 1
    I am facepalming myself right now about this error. Thank you kind sir. – Morningas Nov 14 '16 at 15:32