.

Collection was modified; enumeration operation may not execute

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))

What's your thoughts on this?

*

Protected by WP Anti Spam