哈希表的匹对 两个哈希表之间如何判断是不是一样 如果不一样怎么输出不一样的列 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 因为hashtable默认是FIFO的存储模式.所以要比较的话,先得把两个对象内的数据按相同的规则排序.然后再逐项比较.得出不一样的列. 不好意思.上面讲错了,不是FIFO.只是无序存储. 循环第一个hash表的键值,然后看第2个里面有没有,有的话再判断value是不是相同 HashTable ht1 = new HashTable();HashTable ht2 = new HashTable();ht1.Add(1,1);ht1.Add(2,2);ht1.Add(3,3);ht2.Add(2,2);ht2.Add(3,3);ht2.Add(4,4);IDictionaryEnumerator ide = ht1.GetEnumerator();HashTable table = new HashTable();while(ide.MoveNext()){ if(!ht2.ContainsKey(ide.Key)) { table.Add("ht1有但ht2没有的Key:"+ide.Key.ToString(),ide.Value); } else { if(!ht2.ContainsValue(ide.Value)) { table.Add(ide.Key,"两者都有相同Key但Value不一样的ht1中的Value:"+ide.Value.ToString()); } } }ide = ht2.GetEnumerator();while(ide.MoveNext()){ if(!ht1.ContainsKey(ide.Key)) { table.Add("ht2有但ht1没有的Key:"+ide.Key.ToString(),ide.Value); } else { if(!ht1.ContainsValue(ide.Value)) { table.Add(ide.Key,"两者都有相同Key但Value不一样的ht2中的Value:"+ide.Value.ToString()); } } }if(table.Count>0){ ide = table.GetEnumerator(); while(table.MoveNext()) Console.WriteLine(table.Key.ToString()+","+table.Value.ToString());}else Console.WriteLine("两个哈希表是一样的"); 关于 DataGridView 默认选中行的问题? C# 中 使用TreeView选中checkbox项 ,怎么判断node项的checkbox被选中,怎么选中checkbox 请问Invalidate方法--重绘 谁有用C#写的mis程序,能发给我一份吗? 关于聊天程序问题,帮帮忙,鸭梨大鸭梨大 一个很菜的问题 c#如何写入内容到win8系统的注册表 关于WIN8 RichTextBlock的问题 数据库 文本框 透明 排序 新人,想请教关于水晶报表setparametervalue方法的问题 多线程如何调用窗口 使用Split
所以要比较的话,先得把两个对象内的数据按相同的规则排序.然后再逐项比较.得出不一样的列.
HashTable ht1 = new HashTable();
HashTable ht2 = new HashTable();
ht1.Add(1,1);
ht1.Add(2,2);
ht1.Add(3,3);
ht2.Add(2,2);
ht2.Add(3,3);
ht2.Add(4,4);
IDictionaryEnumerator ide = ht1.GetEnumerator();
HashTable table = new HashTable();
while(ide.MoveNext())
{
if(!ht2.ContainsKey(ide.Key))
{
table.Add("ht1有但ht2没有的Key:"+ide.Key.ToString(),ide.Value);
}
else
{
if(!ht2.ContainsValue(ide.Value))
{
table.Add(ide.Key,"两者都有相同Key但Value不一样的ht1中的Value:"+ide.Value.ToString());
}
}
}
ide = ht2.GetEnumerator();
while(ide.MoveNext())
{
if(!ht1.ContainsKey(ide.Key))
{
table.Add("ht2有但ht1没有的Key:"+ide.Key.ToString(),ide.Value);
}
else
{
if(!ht1.ContainsValue(ide.Value))
{
table.Add(ide.Key,"两者都有相同Key但Value不一样的ht2中的Value:"+ide.Value.ToString());
}
}
}
if(table.Count>0)
{
ide = table.GetEnumerator();
while(table.MoveNext())
Console.WriteLine(table.Key.ToString()+","+table.Value.ToString());
}
else
Console.WriteLine("两个哈希表是一样的");