Collection was modified; enumeration operation may not execute

by pietman 27. June 2011 11:26

I get an error as follows:
Collection was modified; enumeration operation may not execute

for the following code:

 

foreach (Comment comment in comments)
{
    if (comment.IP == IPtoBan)
    {
        p.RemoveComment(comment);
    }
}

 

you can fix this by replacing the first line with this:

foreach (Comment comment in new System.Collections.Generic.List<Comment>(comments))

Tags:

c# | Errors

Add c0mment




  Country flag
biuquote
  • Comment
  • Preview
Loading


About ...

pietman celliersPietman Celliers
Bitlink  Ltd
bitlinkit.com