I am trying to remove object while I am iterating through Collection. But I am getting exception. How can I achieve this? Here is my code :
foreach (var gem
Collections support foreach statement using Enumarator. Enumerators can be used to read the data in the collection, but they cannot be used to modify the underlying collection. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated and the next call to MoveNext or Reset throws an InvalidOperationException. Use for loop for collection modifying.