Collection was modified; enumeration operation may not execute - why?

前端 未结 7 1748
南方客
南方客 2020-11-30 11:38

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

相关标签:
7条回答
  • 2020-11-30 12:18

    The reason you see this is The IEnumerator returned by the underlying collection may expose the current property as read-only. Generally, you should avoid changes to collections(in fact most cases you will not even be able to change the collection) using for-each.

    0 讨论(0)
提交回复
热议问题