System.IndexOutOfRangeException: Индекс находился вне границ массива - C# (182029)
Формулировка задачи:
Всем привет.В чем проблема?
System.IndexOutOfRangeException: Индекс находился вне границ массива.
в Example.Summa(Int32[,] arr) в c:\Program.cs:строка 48
в Example.Main(String[] args) в c:\Program.cs:строка 29
using System;
public class Example
{
public static void Main(string[] args)
{
Console.Write("Размерность квадратной матрицы ");
int y = int.Parse(Console.ReadLine());
int[,] matr =new int[y,y];
Console.WriteLine();
Console.WriteLine("Заполни матрицу");
for (int i = 0; i < y; i++)
{
for (int j = 0; j < y; j++)
{
Console.Write("matr["+i+","+j+"]: ");
matr[i, j] = int.Parse(Console.ReadLine());
}
}
int size=matr.Length;
Console.WriteLine(size);
Summa(matr);
}
public static void Summa(int[,] arr)
{
int a=arr.Length;
int summa=0;
for ( int i = 0; i < (a); i++)
{
for (int j= 0; j < (a); j++)
{
summa=summa+arr[j,i]; }}
Console.WriteLine(summa);
Console.ReadKey();}
}Решение задачи: «System.IndexOutOfRangeException: Индекс находился вне границ массива»
textual
Листинг программы
int a=arr.GetLength(0);