I need to access to a dictionary by its index like a string array.
Dictionary<string, string> tdmDx1 = new Dictionary<string, string>();
for (int item = 0; item < tdmDx1.Count; item++) {
.... how access item by its index ???
}
Sam
Paul E Collins - 28 Apr 2008 00:09 GMT
> I need to access to a dictionary by its index like a string array.
> Dictionary<string, string> tdmDx1 = new Dictionary<string, string>();
> for (int item = 0; item < tdmDx1.Count; item++) {
> .... how access item by its index ???
foreach (KeyValuePair<string, string> kv in tdmDx1)
Eq.
Brian Gideon - 28 Apr 2008 00:43 GMT
On Apr 27, 5:42 pm, skne...@gmail.com wrote:
> I need to access to a dictionary by its index like a string array.
> Dictionary<string, string> tdmDx1 = new Dictionary<string, string>();
[quoted text clipped - 5 lines]
>
> Sam
You can't because the Dictionary class is implemented with a hashtable
so the index doesn't make much sense. Let me ask you this...what
would you want the index value of 0 to mean? That might help us
determine what kind of collection best fits your needs.
Tantr Mantr - 28 Apr 2008 10:05 GMT
Sam, Not sure why you need to loop thru a dictionary using index, but have
you had a look at wintellect's power collections
(http://www.wintellect.com/PowerCollections.aspx). The OrderedDictionary
might be what you are looking for.
Cheers!
> I need to access to a dictionary by its index like a string array.
> Dictionary<string, string> tdmDx1 = new Dictionary<string, string>();
[quoted text clipped - 5 lines]
>
> Sam