News for hackers. Stuff that matters.
Re:What's wrong with this code, really? by StrawberryFrog on Friday September 16, 2011 @11:00AM (#3004689)
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"

There are no comments on this comment yet.