c# - 检查哈希表集合中是否存在键/值对

标签 c# hashtable

我有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/

相关文章:

c# - Visual Studio 2010 中的 Ajax Accordion,有解决方案吗?

dictionary - 为什么 F#'s idiomatic dictionary collection (Map<K,V>) needs the type K to implement comparable while C#' s Dictionary<K,V> 没有?

JavaScript 数据结构捕获一对值作为键及其值

C# Hashtable 不保留值

javascript - js中删除数组元素?

c# - 如何将 .wav 格式的声音附加到彼此

c# - 在 Entity Framework 中查询今天的记录

c# - VS/C# 调用方法时自动生成命名参数

c# - HTML : how do I avoid table tag when using display: table; 中的 iText 7 可访问 PDF

java - 查找数组中两个数字的总和是否等于 k