Collection was modified; enumeration operation may not execute - why?
Posted
by
contactmatt
on Stack Overflow
See other posts from Stack Overflow
or by contactmatt
Published on 2010-12-27T00:53:56Z
Indexed on
2010/12/27
1:53 UTC
Read the original article
Hit count: 575
c#
|enumeration
I'm enumerating over a collection that implements IList, and during the enumeration I am modifying the collection. I get the error, "Collection was modified; enumeration operation may not execute."
I want to know why this error occurs when modifying a item in the collection during iteration. I've already converted my foreach loop to a for loop, but I want to know the 'details' on why this error occurs.
© Stack Overflow or respective owner