[英]how to display 2D array in C# windows form?
I don't know how to display it on a listboxt when I try to put code to display it error always occurs当我尝试放置代码以显示它时,我不知道如何在 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]);
}
Try doing it like this :尝试这样做:
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;
}
You are using j
after you get out of the for (int j = 0; j != arrayCols; j++){ ... }
structure.在退出
for (int j = 0; j != arrayCols; j++){ ... }
结构后,您正在使用j
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.