C# 检查哈希表集合中是否存在键/值对
我有一张桌子C# 检查哈希表集合中是否存在键/值对,c#,hashtable,C#,Hashtable,我有一张桌子 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.ContainsKeyvalue函数检查天气键是否存在,并且ContainsValue函数检查天气值是否存在。但如果我试过 if( hash.Contains("c") &
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
value函数检查天气键是否存在,并且ContainsValue
函数检查天气值是否存在。但如果我试过
if( hash.Contains("c") && hash.ContainsValue("3"))
{
// some code heree
}
对于“c,3”和“c,4”组合,它都将返回true
我需要检查键/值对组合如何检查?您可以检查键是否存在,然后检查相应键的值
if(hash.ContainsKey("c") && hash["c"] == "3") { }
if(hash.ContainsKey("key") && hash["key"] == "3")
{
// contains key and value
}
不管天气是晴朗的,还是恶劣的,不管天气是冷是热,不管我们喜欢与否,我们都会经受住天气的考验。真的吗?你可以给哈希表添加一个重复的键?!Hashtable是一个非通用字典,据我所知,所有字典都拒绝添加重复的键。。。