Collection was modified; Enumeration operation may not execute. Exception handling

Source: Internet
Author: User

Collection was modified; Enumeration operation may not execute. Exception handling

When you run the program, you encounter such an exception, and after careful examination, you find that you are using foreach ... The in syntax is caused by the remove or add to collection, just change the Foreach method to the For method.

    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 Deali                        TEM = 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.DDCRMREPORTST                            ATUs = false;                            Dtdealwrapper.update (Dtdeal);                            String Linecode = "Dd_no:" + dtdeal.ddno;                        Recorddeletelog (Hfdealguid.value, Linecode); }                                          }                }            }

  

Collection was modified; Enumeration operation may not execute. Exception handling

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.