![](/img/trans.png)
[英]Add an item to an already existing 2D integer array in a function in windows form C#
[英]how to display 2D array in C# windows form?
當我嘗試放置代碼以顯示它時,我不知道如何在 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;
}
在退出for (int j = 0; j != arrayCols; j++){ ... }
結構后,您正在使用j
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.