How to remove elements from a generic list while iterating over it?
Iterate your list in reverse with a for loop: for (int i = safePendingList.Count – 1; i >= 0; i–) { // some code // safePendingList.RemoveAt(i); } Example: var list = new List<int>(Enumerable.Range(1, 10)); for (int i = list.Count – 1; i >= 0; i–) { if (list[i] > 5) list.RemoveAt(i); } list.ForEach(i => Console.WriteLine(i)); … Read more