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

来源:互联网 发布:js 对象定义方法 编辑:程序博客网 时间:2024/05/21 17:42
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;
}
}
0 0