Collection was modified; enumeration operation may not execute Dictionary 集合已修改;可能无法执行枚举操作
public void ForeachDic()
{
Dictionary dic = new Dictionary();
dic.Add("1", 10);
dic.Add("2", 20);
dic.Add("3", 30);
foreach (KeyValuePair kvp in dic)
{
Console.WriteLine(String.Format("Key:{0}; Value:{1}", kvp.Key, kvp.Value));
dic[kvp.Key] = 100;//此操作会报错:集合已修改;可能无法执行枚举操作。
}
}
解决方法就是我们可以另外创建一个数组来循环修改集合值,代码如下:
private void ForeachDic()
{
Dictionary dic = new Dictionary();
dic.Add("1", 10);
dic.Add("2", 20);
dic.Add("3", 30);
String[] keyArr = dic.Keys.ToArray();
for (int i = 0; i
Collection was modified; enumeration operation may not execute Dictionary 集合已修改;可能无法执行枚举操作的更多相关文章
- List使用Foreach 修改集合时,会报错的解决方案 (Error: Collection was modified; enumeration operation may not execute. ) - 摘自网络
当用foreach遍历Collection时,如果对Collection有Add或者Remove操作时,会发生以下运行时错误: "Collection was modified; enume ...
- 解决Collection was modified; enumeration operation may not execute异常
今天在使用foreach循环遍历list集合时,出现Collection was modified; enumeration operation may not execute.这个错误,查了半天才发 ...
- C# Collection was modified;enumeration operation may not execute
一.问题描述 在做 数组.列表.集合遍历时,可能我们会遇见这个问题.Collection was modified;enumeration operation may not execute ,翻译的 ...
- Collection was modified; enumeration operation may not execute.的异常处理
Collection was modified; enumeration operation may not execute.的异常处理 在运行程序时遇到这样一段异常,仔细检查后发现是使用Foreac ...
- Error: Collection was modified; enumeration operation may not execute.
http://blog.csdn.net/ffeiffei/article/details/6131254
- [Robot Framework] Robot Framework用Execute Javascript对XPath表示的元素执行scrollIntoView操作
有些元素需要通过滚动条滚动才能变得可见. 如果这些元素在DOM结构里面存在,可以通过scrollIntoView让其可见,但如果在DOM结构里面不存在那就要通过拖动滚动条让其变的可见. Execute ...
- [Robot Framework] Robot Framework用Execute Javascript对XPath表示的元素执行Click操作
Execute Javascript document.evaluate("//a[contains(@href,'createBook')]", document, null, ...
- svn执行update操作后出现:Error : Previous operation has not finished; run 'cleanup' if it was interrupted.
svn执行update操作后出现: Error : Previous operation has not finished; run 'cleanup' if it was interrup ...
- 关于struts2的checkboxlist、select等标签发生could not be resolved as a collection/array/map/enumeration/iterator type异常的记录
1 刚进入该界面的时候发生错误,原因是 list="roles"中的这个集合是空的,导致错误 解决办法很简单,不能让list为空 2 刚进入该界面的时候list是有数据的,当点击提 ...
随机推荐
- JMeter选择协议踩过的坑
- Flink的流处理--KeyBy
逻辑上将一个流分成不相交的分区,每个分区包含相同键的元素.在内部,这是通过散列分区来实现的 object Keyby { def main(args: Array[String]): Unit = { ...
- 微信获取地理位置转城市demo
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js ...
- BZOJ2527 [Poi2011]Meteors 整体二分 树状数组
原文链接http://www.cnblogs.com/zhouzhendong/p/8686460.html 题目传送门 - BZOJ2527 题意 有$n$个国家. 太空里有$m$个太空站排成一个圆 ...
- day 69 orm操作之表关系,多对多,多对一(wusir总结官网的API)
对象 关系 模型 wusir博客地址orm官网API总结 django官网orm-API orm概要: ORM 跨表查询 class Book(models.Model): title = mod ...
- Manager解决Process进程之间的数据访问
import multiprocessing mgr = mutiprocessing.Manager() 开启一个守护子进程,并返回用来与其通信的管理器 share_list = mgr.list( ...
- API接口设计,rest,soap
REST之前的重要协议SOAP rest(简单理解风格.约束.设计理念) rest之前是SOAP:SOAP Web API采用RPC风格,它采用面向功能的架构,所以我们在设计SOAP Web API的 ...
- cookie的基本操作
设置,读取,删除 var odate=new Date(); odate.setDate(odate.getDate()+14); document.cookie='user=blue;expires ...
- 【JavaScript】jQuery
No1: jQuery能帮我们干这些事情: 消除浏览器差异:你不需要自己写冗长的代码来针对不同的浏览器来绑定事件,编写AJAX等代码: 简洁的操作DOM的方法:写$('#test')肯定比docume ...
- CSS-样式篇
2文本: 1文本缩进:text-indent:理论上只有块级元素才可以设置(百分比是相对于父元素的宽度,负值的话要设置内边距进行抵消,防止超过浏览器边界),行内元素可以通过内边距和外边距来达到同样的效 ...