gpt4 book ai didi

c# - 如何更改列表框中项目的名称/字符串?

转载 作者:行者123 更新时间:2023-12-02 22:22:14 24 4
gpt4 key购买 nike

以这种方式添加项目后:

for (int x = 1; x <= 50; x++)
{
listBox1.Items.Add("Item " + x.ToString());
}

我想知道如何在进行更改后更新他们的名字。在代码中。假设我想更改索引 5 处的项目的名称,我该怎么做?

显然这样的事情是行不通的:

listBox1.Items[5].???? = "new string";

最佳答案

只是

listBox1.Items[5] = "new string";

ListBox.ObjectCollection 是实现IList 的项目集合。将给项目本身的索引。所以你可以直接分配它。

关于c# - 如何更改列表框中项目的名称/字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13519328/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com