同意楼上的Hashtable ht1 = new Hashtable(); Hashtable ht2 = new Hashtable();ht1.Add("a", "b");foreach (object h in ht1.Keys) { ht2.Add(ht1[h], h); } h1的key 对应了 h2的value h1的value 对应了 h2的key
可以,遍历就可以了,不过,可能发现有多个Key,(有多个对应的时候,2楼的方法就挂了) Hashtable ht = new Hashtable();//... object value = null; ArrayList result = new ArrayList(); foreach (DictionaryEntry entry in ht) { if (entry.Value == value) result.Add(entry.Key); }
Hashtable ht2 = new Hashtable();ht1.Add("a", "b");foreach (object h in ht1.Keys)
{
ht2.Add(ht1[h], h);
}
h1的key 对应了 h2的value
h1的value 对应了 h2的key
Hashtable ht = new Hashtable();//...
object value = null;
ArrayList result = new ArrayList();
foreach (DictionaryEntry entry in ht)
{
if (entry.Value == value)
result.Add(entry.Key);
}