Collection was modified; enumeration operation may not execute

后端 未结 16 2612
南旧
南旧 2020-11-21 06:05

I can\'t get to the bottom of this error, because when the debugger is attached, it does not seem to occur.

Collection was modified; enumeration operatio

16条回答
  •  猫巷女王i
    2020-11-21 06:43

    Okay so what helped me was iterating backwards. I was trying to remove an entry from a list but iterating upwards and it screwed up the loop because the entry didn't exist anymore:

    for (int x = myList.Count - 1; x > -1; x--)
    {
        myList.RemoveAt(x);
    }
    

提交回复
热议问题