【发布时间】:2014-05-23 12:41:58
【问题描述】:
在 (private int >>>TotArray
这段代码的作用是把这个二维数组的所有数字相加。 但此刻它什么也没做。
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);
}
【问题讨论】:
标签: c# arrays methods multidimensional-array