循环遍历不同的ListBox

Loop through different ListBox

我有多个名为 Box0、Box1、Box2 等的列表框。 我想在每个Box中添加对应的数组元素,但不知道如何调用它们。
应该是这样的:

for (int i = 0; i < 10; i++)
{
    Box[i].Items.Add(array[i]);
}

最好创建一个 List<ListBox> 框,将所有 listboxes 添加到其中,然后像这样循环遍历这些框:foreach (ListBox lb in boxes){..} 或者使用正常的 for 循环,如果您需要索引:for (int i = 0; i < boxes.Count; i++) ){..}

资料来源:Taw 的评论