C# 中的 ContainsValue
在 C# 中使用 ContainsValue() 方法搜索 Dictionary 中的值。
创建一个 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");
// search for a value
Console.WriteLine(d.ContainsValue("Two"));
}
}输出
True
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP