Because the space is very short, try writing it all. It's not necessary to finish the text in a few minutes or more than 10 minutes.
The Foreach Traversal list operation is convenient, saving some [] code for data and subscript calculations. It's simple to write. However, if you are traversing delete, you will encounter a classic iterator invalidation problem.
A common idea to solve this problem is to put a temporary container B on the element that needs to be removed in container a. Then traverse this container b again, remove the element and delete it in a. This is a lot of shortcomings, two cycles, and adding temporary containers, the code is very difficult to see.
In fact, the simplest way to prevent (or avoid encountering) the failure of an iterator is to delete it while traversing the delete. This writing is classic, that is i--some people seem not accustomed to it.
"C # Lazy Egg programming-5 minutes experience sharing" 01 reverse traversal Delete to prevent iterator invalidation