博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
关于foreach中对集合执行Add或者Remove操作引发枚举值被修改异常
阅读量:4355 次
发布时间:2019-06-07

本文共 251 字,大约阅读时间需要 1 分钟。

方法传入集合List<string> ids;

执行操作后再次循环引发异常

foreach (string id in ids)

{
ids.Add("a");
}

更改为for循环可控制循环次数

int ic = ids.Count();

for (int j = 0; j < ic; j++)
{

//验证判断

//if(true)

//{

//ids.Remove(ids[j]);

//}

}

转载于:https://www.cnblogs.com/Tangcy/p/4924069.html

你可能感兴趣的文章
Eclipse搭建springboot项目(八)拦截器、过滤器、监听器
查看>>
JWPlayer Flash播放器分段载入视频以节省带宽的方法分享
查看>>
Oracle OCI-22053:溢出错误解决方法
查看>>
spring MVC junit单元测试 各test之间共享变量
查看>>
tomcat thread dump 分析【转载】
查看>>
myeclipse中java文件头注释格式设置
查看>>
redis基础之redis-sentinel(哨兵集群)(六)
查看>>
Linsheng Electrical Company . - Car Air Pump: What Effect?
查看>>
uva 10801(最短路)
查看>>
samtools的一些问题
查看>>
实用R函数
查看>>
微屁嗯
查看>>
@perproty and @synthesize
查看>>
java - 分页类
查看>>
SpringBoot2 上传文件 上传多文件
查看>>
进程、线程、协程
查看>>
Discuz! 论坛软件系统简介
查看>>
Python之学习菜鸟教程踩的坑
查看>>
js上传图片前预览方法(支持预览多个图片)
查看>>
hdu 1295 Move Move Look
查看>>