Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any alternative of Dictionary in .NET?

I have a requirement of using a dictionary in the project but as we know that they are only accessible using the keys and not using the indexes, and I want to access the items in dictionary using indexes. So I fiddle over the web and found out about OrderedDictionary as they are accessible using both the indexes and keys but they have some performance issue and as I am reading/writing the dictionary every minute of the day so it's not a good idea to use OrderedDictionary.

So lastly my question in here is that is there any alternative available which gives me functionality of Dictionary and I can also access it using indexes and doesn't cause a performance issue.

like image 579
Safran Ali Avatar asked Dec 17 '22 09:12

Safran Ali


1 Answers

SortedList<TKey, TValue> has a property, Values, that is an IList<TValue>. Is it enough? It's fast only for small "sets" of elements. The difference with SortedDictionary is here http://msdn.microsoft.com/en-us/library/5z658b67(v=vs.80).aspx

Can I ask you why you want to access it "by index"? You can still enumerate it with foreach, you know?

like image 104
xanatos Avatar answered Dec 22 '22 01:12

xanatos