I\'ve always thought otherwise, but recently I had the need to know:
If I add elements to a list in a certain order, am I guaranteed to find then always on the same
Yes; you control the ordering of a List
.
You can assume that any .NET collection with a list[int]
indexer has a predictable ordering; otherwise, the numerical index wouldn't make any sense. By comparison, it's not possible to use a numerical index with a Dictionary
, and when you enumerate a dictionary, the ordering isn't guaranteed.