Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在C#windows窗体中显示二维数组?_C# - Fatal编程技术网

如何在C#windows窗体中显示二维数组?

如何在C#windows窗体中显示二维数组?,c#,C#,我不知道如何在listboxt上显示它,当我试图把代码显示它时,错误总是发生 int arrayRows = 5; int arrayCols = 3; int[,] arrayTimes; arrayTimes = new int[arrayRows , arrayCols]; int mult = 0; for (int i = 0; i != arrayRows; i++) { mult = mult + 10; for (int j = 0; j != arrayCo

我不知道如何在listboxt上显示它,当我试图把代码显示它时,错误总是发生

int arrayRows = 5;
int arrayCols = 3;

int[,] arrayTimes;
arrayTimes = new int[arrayRows , arrayCols];
int mult = 0;

for (int i = 0; i != arrayRows; i++)
{
    mult = mult + 10;
    for (int j = 0; j != arrayCols; j++)
    {
        arrayTimes[i, j] = mult;
        mult = mult * 10;
    }

    mult = mult / 1000;
    listBox1.Items.Add("arrayPos= " + i + "values =" + arrayTimes[i,j]);            
}

试着这样做:

int arrayRows = 5;
int arrayCols = 3;

int[,] arrayTimes;
arrayTimes = new int[arrayRows , arrayCols];
int mult = 0;

for (int i = 0; i != arrayRows; i++)
{
    mult = mult + 10;
    for (int j = 0; j != arrayCols; j++)
    {
        arrayTimes[i, j] = mult;

        listBox1.Items.Add("arrayPos= " + i + "values =" + arrayTimes [i,j]);

        mult = mult * 10;
    }
    mult = mult / 1000;
}

在退出(int j=0;j!=arrayCols;j++){…}结构后,您正在使用
j

发生了什么错误?此代码甚至不会编译。您试图在其范围之外使用j。
for(int i=0;i!=arrayRows;i++)
永远不要使用该结束条件。而是使用
i
如果由于某些原因,
i
变得大于
arrayRows
?输出应如下:arrayPos=0,0 val=10 arrayPos=0,1 val=100 arrayPos=0,2 val=1000 arrayPos=1,0 val=20 arrayPos=1,1 val=200 arrayPos=1,2 val=2000 arrayPos=2,0 val=30 arrayPos=2,1 val=300 arrayPos=2,2 val=3000 arrayPos=3,0 val=40 arrayPos=3,1 val=400arrayPos=3,2 val=4000 arrayPos=4,0 val=50 arrayPos=4,1 val=500 arrayPos=4,2 val=5000但您遇到了什么错误?请帮助我,我是C#编程新手