The exception is thrown because, foreach loop calls collectionName.GetEnumerator method before it starts iterating through the list of items. GetEnumerator is not called again unless you start a new foreach loop on the collection. The list cannot be modified inside the foreach loop, it is meant only for read-only operations on the list.
You may use for loop for iterating as well as modifying the elements from the list.