【发布时间】:2014-05-23 12:08:39
【问题描述】:
我做得对吗?我正在尝试添加这个二维数组的每个数字并显示总数。我认为我在正确的轨道上,但是如果有人可以帮助我,我会被卡住,我非常感谢。
int[,] A = new int[3, 4]
{
{ 4, -5, 12, -2},
{ -9, 15, 19, 6},
{ 18, -33, -1, 7}
};
private void TotArray(int[,] array)
{
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 += A[i, j];
}
}
}
private void button1_Click(object sender, EventArgs e)
{
TotArray(A);
}
【问题讨论】:
-
那有什么问题?
-
@MattBurland 问题是它什么都不显示
标签: c# arrays methods multidimensional-array