我有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"组合是否已经存在于哈希表中。
hash.ContainsKey
值函数检查天气键是否存在,ContainsValue
函数检查天气值是否存在。但如果我尝试过
if( hash.Contains("c") && hash.ContainsValue("3"))
{
// some code heree
}
它会为“c,3”和“c,4”组合返回 true。
我需要检查键/值对组合,我该如何检查?
最佳答案
if(hash.ContainsKey("c") && hash["c"] == "3") { }
关于c# - 检查哈希表集合中是否存在键/值对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15198718/