I guess everything is in the title...
I know that Dictionary<TKey,TValue>
does keep the keys in addition order, but only as long as you don't remove any, and anyway this behavior is not documented and can't be relied upon (see this question for details).
Basically, what collection should I use if I want an ordered collection of key/value pairs, while keeping an O(1) access time? (List<KeyValuePair<K,V>>
isn't a good option since it would have O(n) access time). I don't think there is anything like that in the BCL, but I just want to be sure before I roll my own...
Just to make it clear to everyone: I don't want the keys to be sorted, I just want them to remain in addition order. So SortedList
/SortedDictionary
are not what I'm looking for...