比较循环中两个哈希表的值 [英] Compare values of two hash tables in loop

查看:121
本文介绍了比较循环中两个哈希表的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个哈希表.我想根据密钥比较两个哈希表的值.我想循环执行此操作,如果找到匹配项,则要执行字符串构建操作.但是问题是我不知道有什么机制可以循环比较它们.请指导我... 以下是我要比较的哈希表

I have two hash tables. I want to compare values of both the hash tables based on the key. I want to do this in loop and if match is found is want to perform string building operation. But the problem is I dont know any mechanism to compare them in loop. Please guide me... Following are my hash tables to be compared

       HashTable OldTable= new HashTable();

        OldTable.Add("Date of Event", OCEFData.EventDate);
            OldTable.Add("Angina Status", OCEFData.AnginaStatusValue);
            OldTable.Add("Please indicate the body system involved (tick all that apply)",strBodySystem.ToString());
            OldTable.Add("If Unstable Angina, define Braunswald Classification", OCEFData.UnstableAnginaValue);
            OldTable.Add("If Stable Angina", OCEFData.StableAnginaValue);
            OldTable.Add("Details of method of Documentation of Angina", OCEFData.AnginaDocDetails);
            OldTable.Add("INFORM TO SPONSOR", (OCEFData.IsInformed)?"Yes":"No");
            OldTable.Add("DATE OF INFORMATION TO SPONSOR ", OCEFData.SponsorDate);
            OldTable.Add("DATE OF INFORMATION TO INSTITUTIONAL ETHICS COMMITTEE", OCEFData.EthicsCommitteeDate);
            OldTable.Add("DATE OF INFORMATION TO LICENSING AUTHORITY", OCEFData.LicensingAuthority);



       HashTable NewTable= new HashTable();

       NewTable.Add("Date of Event", OCEFData.EventDate);
        NewTable.Add("Angina Status", OCEFData.AnginaStatusValue);
        NewTable.Add("Please indicate the body system involved (tick all that apply)", strBodySystem.ToString());
        NewTable.Add("If Unstable Angina, define Braunswald Classification", OCEFData.UnstableAnginaValue);
        NewTable.Add("If Stable Angina", OCEFData.StableAnginaValue);
        NewTable.Add("Details of method of Documentation of Angina", OCEFData.AnginaDocDetails);
        NewTable.Add("INFORM TO SPONSOR", (OCEFData.IsInformed)?"Yes":"No");
        NewTable.Add("DATE OF INFORMATION TO SPONSOR ", OCEFData.SponsorDate);
        NewTable.Add("DATE OF INFORMATION TO INSTITUTIONAL ETHICS COMMITTEE", OCEFData.EthicsCommitteeDate);
        NewTable.Add("DATE OF INFORMATION TO LICENSING AUTHORITY", OCEFData.LicensingAuthority);

推荐答案

这是您想要的方式吗?

Hashtable OldTable = new Hashtable();
Hashtable NewTable = new Hashtable();

        foreach (DictionaryEntry entry in OldTable)
        {
            if(NewTable.ContainsKey(entry.Key))
            {
                //Do something?
            }
        }

这篇关于比较循环中两个哈希表的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆