0

I am getting error when using foreach with ObservableCollection.

Collection was modified; enumeration operation may not execute.

How should I handle this error?

Jakob
  • 37
  • 8
  • Don't modify the collection while enumerating. Try putting a `.ToArray()` after the collection in the `foreach` loop. Next time, also post your code please. – Enigmativity Sep 20 '17 at 01:19
  • `How should I handle this error?` it depends on your case. a problem can be handled in many ways. – M.kazem Akhgary Sep 20 '17 at 01:25
  • I am not sure it is best practice. Anyway I resolved by decreasing index backward. – Jakob Sep 20 '17 at 01:35

0 Answers0