Getting an error at (private int >>>TotArray<< (int[,] array)) Which tells me I cannot return value. Can anyone help me and tell me what I am doing wrong?
What this code does is it supposed to add all the numbers of this 2 dimensional array. But in the moment it does nothing.
int[,] A = new int[3, 4]
{
{ 4, -5, 12, -2},
{ -9, 15, 19, 6},
{ 18, -33, -1, 7}
};
public Form1()
{
InitializeComponent();
}
private int TotArray(int[,] array)//<<<<<< error
{
int sum = 0;
int rows = array.GetLength(0);
int cols = array.GetLength(1);
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
sum += array[i, j];
}
}
richTextBox1.Text = ("The sum of the array is " + sum.ToString() + ".");
}
private void button1_Click(object sender, EventArgs e)
{
TotArray(A);
}