gpt4 book ai didi

c# - 集合被修改;枚举操作可能无法执行

转载 作者:太空狗 更新时间:2023-10-30 00:09:02 28 4
gpt4 key购买 nike

<分区>

这个问题在这个论坛被问了很多次。我知道问题的解决方案。但是我很好奇为什么“修改集合时无法执行枚举操作”

        List<string> list = new List<string>();

list.Add("a");

list.Add("b");

int[] array = new int[6] { 1, 2, 3, 4, 5, 5 };

HashSet<int> hashSet = new HashSet<int>();

int i = 0;

foreach (string s in list)
{
list[i] = "test";

i++;
}

但是当我将列表更改为 list.toarray 时它起作用了。

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