How can I remove all the items of a list? I do not know any thing about how the items get indexed, thats why I cannot provide a better code except this..

for (int i = 0; i < _Cars.Count; i++)

6 Years
Discussion Span
Last Post by Geekitygeek

Also, i realise you aren't going to use your code. But for future reference, if you are going to remove items from a collection in a for loop you should always start at the highest index and work back to zero. Otherwise, when you remove an item, the indexes all shift down one; the result is that you skip the next item and you risk an exception when you get to the last index because the collection is smaller than when you started.

You should use something like:

for(int i = _Cars.Count; i>=0; i--)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.