Collection was modified; enumeration operation may not execute.的异常处理
在运行程序时遇到这样一段异常,仔细检查后发现是使用Foreach...In语法体内运用了对Collection的Remove或Add导致的,只需要将foreach方法改为for方法即可。
for (int i = 0; i < this.prtdeallist.Items.Count; i++)
{
RepeaterItem repeaterItem = this.prtdeallist.Items[i]; if (repeaterItem.ItemType == ListItemType.Item || repeaterItem.ItemType == ListItemType.AlternatingItem)
{
HtmlInputCheckBox cbDealIsSelected = repeaterItem.FindControl("ckPpGuid") as HtmlInputCheckBox;
HiddenField hfDealGuid = repeaterItem.FindControl("HiddenField2") as HiddenField;
if (cbDealIsSelected.Checked )
{
DTDealItemWrapper DealItem = DTDealItemWrapper.FindById(hfDealGuid.Value);
DTDealWrapper DTdeal = null;
if (DealItem == null)
{
DTdeal = DTDealWrapper.FindById(hfDealGuid.Value);
}
if (DealItem != null)
{
DealItem.DDICRMReportStatus = false;
DTDealItemWrapper.Update(DealItem);
string LineCode = "LineCode:" + DealItem.DDILineCode;
RecordDeleteLog(hfDealGuid.Value, LineCode);
}
else if (DTdeal != null)
{
DTdeal.DDCRMReportStatus = false;
DTDealWrapper.Update(DTdeal);
string LineCode = "DD_NO:" + DTdeal.DDNo;
RecordDeleteLog(hfDealGuid.Value, LineCode);
} } }
}
Collection was modified; enumeration operation may not execute.的异常处理的更多相关文章
- 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 ,翻译的 ...
- Error: Collection was modified; enumeration operation may not execute.
http://blog.csdn.net/ffeiffei/article/details/6131254
- Collection was modified; enumeration operation may not execute Dictionary 集合已修改;可能无法执行枚举操作
public void ForeachDic() { Dictionary dic = new Dictionary(); dic.Add("1", 10); dic.Add(&q ...
- 关于struts2的checkboxlist、select等标签发生could not be resolved as a collection/array/map/enumeration/iterator type异常的记录
1 刚进入该界面的时候发生错误,原因是 list="roles"中的这个集合是空的,导致错误 解决办法很简单,不能让list为空 2 刚进入该界面的时候list是有数据的,当点击提 ...
- Result Maps collection does not contain value for java.lang.Integer异常处理
使用Mybatis的时候出现这个问题是因为配置文件的问题造成的,mybatis需要写大量的配置文件, 尽管有mybatis-generator,但是里面的内容有很多还是要自己去写的,在这过程中难免会出 ...
- 做WP程序时遇到的一些问题及解决方法
问题1:Type 'JDBYSJ.Data.NewsChannel' cannot be serialized. Consider marking it with the DataContractAt ...
- C# 使用Linq递归查询数据库遇到的问题及解决方法
User表通常是我们在写"XX管理系统"项目时必须要用到的,有的情况下人员的分类属于树形结构,就是除了最高层和最低层,中间层都有相对的父和子,设计数据库的时候,我们通常会加一个pa ...
随机推荐
- 最好用的中文速查表(Bash,Gdb,VIM,Nano)
最好用的中文速查表(Cheatsheet) 当年学习 Linux 时就是靠着一张常用命令小卡片,敲啥命令忘记了,经常拿起来看看,后来知道这玩意儿叫做速查表(Cheatsheet),于是开始有意识收集和 ...
- Operating system coordinated thermal management
A processor's performance state may be adjusted based on processor temperature. On transitions to a ...
- Hive分析窗体函数之NTILE,ROW_NUMBER,RANK和DENSE_RANK
開始,依照顺序,生成分组内记录的序列–比方,依照pnum降序排列.生成分组内每天的pnum名次ROW_NUMBER() 的应用场景许多.再比方,获取分组内排序第一的记录等等. SELECT polno ...
- Qt的paint函数重写,以及QPaint给一条线绘制箭头
直接代码: QPainter *painter; static const double Pi = 3.14159265358979323846264338327950288419717; stati ...
- Vue中import '@...'是什么
今天看新项目代码,有import '@/assets/css/theme/index.css'一类的代码,里面的@是做什么的呢. 找到这篇文章https://www.cnblogs.com/bos ...
- ant的condition任务
1.istrue isfalse:断言 真 假 <project name="testCondition"> <target name="test&qu ...
- Hibernate综合问题
n + 1问题 query.iterate()信息返回迭代查询将开始发表声明:录ID语句 Hibernate: select student0_.id ascol_0_0_from t_student ...
- hudson搭建经验总结(二)
作者:朱金灿 来源:http://blog.csdn.net/clever101 继续部署hudson,发现从google上的一个开源工程上:http://code.google.com/p/huds ...
- Java编程思想学习笔记-使用显式的Lock对象
若要保证后台线程在trylock()之前运行得到锁,可加“屏障”,如下1,2,3步,而trylock()不管设定时间与否都不会阻塞主线程而是立即返回: //: concurrency/AttemptL ...
- WPF动画旋转(3轴同时旋转问题)
原文:WPF动画旋转(3轴同时旋转问题) WPF的资料比较少,做起来不是很方便,之前一直有个XYZ3个轴同时旋转的问题,开始的时候以为通过 this.theRotateX.Axis = new Ve ...