InvalidOperationException in loop

This issue seems to be raised a lot in the newsgroups. When you iterate a container, ArrayList for instance, you cannot remove items in the contain inside the body of the loop. You get a nasty exception if you have no regard for the rules. Apparently, the run-time imposes a read-only restriction on the iterating container. The read-only restriction forces all assumptions about the container to be valid during the loop iteration process. There’s an article here that discusses this in more detail. Basically, this code produces an exception: //arr is an arraylist with some random items foreach (string s in … Continue reading InvalidOperationException in loop