Is there an collection in .net that allows the storing KeyValuePair<string, string> that keeps the order of inserting?
OrderedDictionary looked promising, but seems to be rather lacking.
Now I’m looking into IOrderedEnumerable>, but I can’t seem to find any implementation except for ISortedDictionary, but that’s not what I want. No sorting needs to be done, just the order of inserting is important.
Update
The reason I don’t like OrderedDictionary is that it’s not generic.
OrderedDictionaryis what you want if you need both keyed and insertion-sequenced access to items … it’s really just a combination of a hash table and a list. It provides a means to access items in it either by insertion index or by key. It’s the only collection in .NET that does this. Sadly, it is not generic.If
OrderedDictionarydoesn’t meet your needs solely because it is not generic – then you can use the version here that provides a generic equivalent. If there are other reasons why it doesn’t work for you, update your post and we can look for a better option.While you can certainly create your own
List<KeyValuePair<string,string>>you will lose the option of searching by key efficiently. Now, you can certainly roll your own implementation of an ordered doctionary that combined list/dict together … but the post I’ve linked to already does this.