c# 判断字典中是否存在值
可以使用字典的ContainsValue()方法来判断字典中是否存在某个值。
示例代码:
Dictionary<string, int> dict = new Dictionary<string, int>();
dict.Add("apple", 1);
dict.Add("banana", 2);
if (dict.ContainsValue(1))
{
Console.WriteLine("字典中存在值为1的键值对");
}
else
{
Console.WriteLine("字典中不存在值为1的键值对");
}
输出结果:
字典中存在值为1的键值对
原文地址: https://www.cveoy.top/t/topic/halF 著作权归作者所有。请勿转载和采集!