C#中如何判断两个哈希表相同Key的值

如题所述

不知道你具体是什么问题,希望这段代码能帮到你:
Hashtable ht = new Hashtable();
Hashtable ht2 = new Hashtable();

ht.Add("Victor", 2000);
ht.Add("Bill", 3000);
ht2.Add("Bill", 1500);
ht2.Add("Michael", 4000);

foreach (string key in ht.Keys)
{
if (ht2.ContainsKey(key))
{
if (ht[key] == ht2[key]) //用这种方法 利用key来从hashtable中取值
{
Console.WriteLine("Key is:{0}, value is {1},equel", key, ht[key]);
}
else
{
Console.WriteLine("Key is:{0}, not equel", key);
}
break;
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-12-01
顶一下