The C#-collection has been modified; enumeration operations may not be performed

Source: Internet
Author: User

Today, when I use the foreach statement to iterate over the dictionary, I find an error:

The collection has been modified; enumeration operations may not be performed

Search the web, and find that foreach is iterative, and it cannot be added and deleted. But, I tried, and found that there was another problem: when comparing and correcting values, it also gives an error, such as:

1 foreach(keyvaluepair<string,Double> soilstrkvinchsoil)2             {3                 if(Isvalidval (soilstrkv.value))4                 {5Soil[soilstrkv.key] =Replaceinvalidval;6                     //sitenumstr = soilStrKV.Key.Substring (0, SoilStrKV.Key.IndexOf ('_'));7                     //Yearstr8                     //Sitesoil.add ();9                 }Ten             } One  A /// <summary> -         ///False indicates a non-conforming value, otherwise conforming. -         /// </summary> the         /// <param name= "inval" ></param> -         /// <returns></returns> -         Private BOOLIsvalidval (Doubleinval) -         { +             returnInval <=Available_val; -}

In line 5th, the error is corrected (when the duplicate value is modified).

The C#-collection has been modified; enumeration operations may not be performed

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.