Finding the Sum of Rows and Columns in a Two-Dimensional Array
using System;
namespace SumRowColumn2dArray
{
class Program
{
static void Main(string[] args)
{
int[,] array = new int[,]
{
{1,2,3,4},
{4,5,6,1},
{7,8,9,0},
};
Console.WriteLine(SumArray(array));
Console.Read();
}
public static int SumArray(int[,] array)
{
int total = 0;
for (int i = 0; i < array.GetLength(0); i++) // row
{
for (int j = 0; j < array.GetLength(1); j++) // column
{
total += array[i, j];
}
}
return total;
}
}
}