C#中的ContainsValue
使用ContainsValue()C#中的方法在Dictionary中搜索值。
创建字典并添加元素-
Dictionary<string, string> d = new Dictionary<string, string>();
d.Add("keyboard", "One");
d.Add("mouse", "Two");现在,使用该ContainsValue()方法查找特定值-
d.ContainsValue("Two");以下是完整的代码-
示例
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
Dictionary<string, string> d = new Dictionary<string, string>();
d.Add("keyboard", "One");
d.Add("mouse", "Two");
//搜索值
Console.WriteLine(d.ContainsValue("Two"));
}
}输出结果
True
热门推荐
10 钢琴人祝福语女生简短
11 岗位考试顺利祝福语简短
12 关于老师蛋糕祝福语简短
13 娘家妈妈新婚祝福语简短
14 生日留言简短祝福语大全
15 祝福语诗意文案简短
16 校长退休文案祝福语简短
17 宝子生日祝福语简短
18 寒露祝福语毕业寄语简短