zoukankan      html  css  js  c++  java
  • 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);
                            }
    
    
                          
                        }
    
                    }
                }
    

      

  • 相关阅读:
    eclipse使用
    模板模式

    异常处理
    内部类
    面向对象三大特征(三)--多态
    java双指针的简单理解
    简单易懂回溯算法
    《深入理解Java虚拟机》之(一、内存区域)
    Java笔记(第七篇 JDBC操作数据库)
  • 原文地址:https://www.cnblogs.com/wangguowen27/p/Collection.html
Copyright © 2011-2022 走看看