When I add an entry to a Dictionary using Add, the KeyValuePair is added at the end of it. I would like to preppend it thus when I iterate on KeyValuePair‘s, it is the first item.
Is there a way to do it with a Dictionary or should I build a List<KeyValuePair<TKey, TValue>> or do you have a better proposition?
EDIT : I thought I could work on the enumeration in Dictionary, it seems I can’t.
I tried with List<KeyValuePair<TKey, TValue>> which was not very practical.
The
Dictionaryclass doesn’t have a concept of order within it – there is no positional index to theDictionary.Take a look at the
OrderedDictionaryclass in theSystem.Collections.Specializednamespace if you need to use a positional index on a dictionary.