3 ms·
A while loop isn't in itself an iterator. There's a difference between while(collection.Count > 0) { collection.Delete(0); } .. which is a working i
by StrawberryFrog 15y ago
A while loop isn't in itself an iterator. There's a difference between
while(collection.Count > 0)
{
collection.Delete(0);
}
.. which is a working implementation of clear, though probably superfluous.
and...
int i = 0;
while(i < collection.Count)
{
collection.Delete(i);
i++;
}
which does try to walk along the list and is broken.
Also, .Net has a specific exception to stop you modifying a collection while an enumerator is walking along it. Google for "Collection was modified; enumeration operation may not execute"