Collection was modified; enumeration operation may not execute
Posted
by
Rita
on Stack Overflow
See other posts from Stack Overflow
or by Rita
Published on 2012-10-04T21:16:53Z
Indexed on
2012/10/04
21:38 UTC
Read the original article
Hit count: 176
I have the below code. I am trying to remove the record and it is throwing Exception when it is removing the Record. "Collection was modified; enumeration operation may not execute."
Any ideas on how to get rid of the message. Appreciate your time.
//validClaimControlNo has valid ClaimControl Numbers.
List<string> validClaimControlNo = new List<string>();
int count = 0;
foreach (List<Field> f in records)
{
foreach (Field fe in f)
{
if (i == 0)
if (!(validClaimControlNo.Contains(fe.Value)))
{
//if this claim is not in the Valid list, Remove that Record
records.RemoveAt(count);
}
i++;
}
i = 0;
count++;
}
© Stack Overflow or respective owner