如何将matrice(2d数组)写入列表框

时间:2016-05-11 10:34:22

标签: asp.net arrays listbox

我尝试过以下代码但是它以垂直方式写入。如何将2d数组添加到我的列表框中

 for (int i = 0; i < test.GetLength(0); i++)
        {
            for (int j = 0; j < test.GetLength(1); j++)
            {
                ListBox3.Items.Add("-" + test[i, j].ToString());

            }
            ListBox3.Items.Add("\n");
        }

        }

1 个答案:

答案 0 :(得分:0)

这可以帮助您从我的查询中理解;

string listboxstr = "";
for (int i = 0; i < test.GetLength(0); i++)
    {
        listboxstr = "" + test[i, 0].ToString();
        for (int j = 1; j < test.GetLength(1); j++)
        {
            listboxstr +="-" + test[i, j].ToString();

        }
        ListBox3.Items.Add(listboxstr);
        ListBox3.Items.Add("\n");
    }

    }