Say I have 3 strings in a List (e.g. “1”,”2″,”3″).

Then I want to reorder them to place “2” in position 1 (e.g. “2”,”1″,”3″).

I am using this code (setting indexToMoveTo to 1):

listInstance.Remove(itemToMove);
listInstance.Insert(indexToMoveTo, itemToMove);

This seems to work, but I am occasionally getting strange results; sometimes the order is incorrect or items from the list are getting deleted!

Any ideas? Does List<T> guarantee order?

Related:

Does a List<T> guarantee that items will be returned in the order they were added?

5 Answers
5

Leave a Reply

Your email address will not be published. Required fields are marked *