When you delete an item in a list, any list, the indexes of the remaining items may change. There are two easy ways to cope with that: 1. not moving at all: assuming a range of items may have to be deleted, if the first item the be deleted is at index x, use RemoveAt(x); and continue testing for more removals at the same index x, as each removal there will decrement the index of all the # subsequent items by one. 2. working backwards: first determine the range to be deleted, without actually deleting anything; then delete from high index to low index; this also works when the items of interest aren't consecutive. Beware, whatever you choose to do, a foreach will fail as an enumerator becomes invalid (and will throw an exception) when the collection gets modified. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
If you want my opinion or comment, ask in a forum or on my profile page; I will not participate in frackin' Q&A