检查哈希表集合中是否存在键/值对 [英] Check whether key/value pair exists in hashtable collection

查看:94
本文介绍了检查哈希表集合中是否存在键/值对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有hastable

I have hastable

Hashtable hash = new Hashtable();
hash.Add("a", "1");
hash.Add("b","2");
hash.Add("c","3");
hash.Add("c","4"

现在,我需要检查Key ="c"和value ="3"组合是否已经在哈希表中退出.

Now I need to check Key = "c" and value= "3" combination is already exits in hashtable or not.

hash.ContainsKey值功能检查天气键是否存在,而ContainsValue功能检查天气值是否存在.但是,如果我尝试过

hash.ContainsKey value function cheks weather key is exists or not and ContainsValue function checks weather value is exists or not. But if I tried

if( hash.Contains("c") && hash.ContainsValue("3"))
{
  // some code heree
}

然后,它对于"c,3"和"c,4"组合都将返回true.

than it will return true for both "c,3" and "c,4" combinathion.

我需要检查键/值对组合,如何检查?

I need to check key/value pair combination how can I check that ?

推荐答案

if(hash.ContainsKey("c") && hash["c"] == "3") { }

这篇关于检查哈希表集合中是否存在键/值对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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