index of hash table

  • Thread starter Thread starter Ching-Lung
  • Start date Start date
C

Ching-Lung

Hi,

How do I get the index of a specific key/value in a hash
table?

Hashtable ht = new Hashtable();
ht.Add("k1", "v1"); // ht[0]
ht.Add("k2", "v2"); // ht[1]
ht.Add("k3", "v3"); // ht[2]
ht.Add("k4", "v4"); // ht[3]
ht.Add("k5", "v5"); // ht[4]

if(ht.ContainsKey("k2")){
// how do I get the index of "k2"?
}

Please help. Thanks.
-CL
 
Hi Ching-Lung,

You can't. Items in the hastables are not ordered.
If you need the ordered them you can keep a parallel List.
HTH
B\rgds
100
 
OK, thanks!

-----Original Message-----
Hi Ching-Lung,

You can't. Items in the hastables are not ordered.
If you need the ordered them you can keep a parallel List.
HTH
B\rgds
100
Hi,

How do I get the index of a specific key/value in a hash
table?

Hashtable ht = new Hashtable();
ht.Add("k1", "v1"); // ht[0]
ht.Add("k2", "v2"); // ht[1]
ht.Add("k3", "v3"); // ht[2]
ht.Add("k4", "v4"); // ht[3]
ht.Add("k5", "v5"); // ht[4]

if(ht.ContainsKey("k2")){
// how do I get the index of "k2"?
}

Please help. Thanks.
-CL


.
 
Back
Top