Link to home
Start Free TrialLog in
Avatar of Kai77
Kai77

asked on

Get key by idex from a ordered dictionary

How can I retrieve the key by using the index?

I can retrieve the value by index like: oOrderedDictionary[0].toString()

Is there something similair for a key value?
(I believe a sortedlist has a GetKey() method, but the ordered dictionary does not?)
Avatar of jonorossi
jonorossi

Have you tried using the TryGetValue method?
Avatar of Kai77

ASKER

I am using ASP.net 2.0 and intellisense does not say OrderDictionary has a TryGetValue method
Is there a reason you are using System.Collections.Specialized.OrderedDictionary instead of System.Collections.Generic.Dictionary<TKey,TValue>
Avatar of Kai77

ASKER

from what i undestand an ordered dictionary the sort order is ordered by the order in which you addes key-value pairs. Does the generic.dictionary do the same?
Avatar of Kai77

ASKER

I just took a quick look at the Generic.Dictionary .

I believe the TryGetValue needs you to enter a key and will return a value based on that key. What I need is to enter a index and get the key.
If you require that the dictionary be sorted then you should use the generic SortedDictionary:

System.Collections.Generic.SortedDictionary<TKey, TValue>
I see what you are after now. I can't seem to find what you are after in any of the collections built into .NET. For some reason none of them allow you to get the key by an index.
ASKER CERTIFIED SOLUTION
Avatar of jonorossi
jonorossi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial