Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
ContainsValue in C#
Use the ContainsValue() method in C# to search for a value in a Dictionary.
Create a Dictionary and add elements −
Dictionary<string, string> d = new Dictionary<string, string>();
d.Add("keyboard", "One");
d.Add("mouse", "Two");
Now, use the ContainsValue() method to find a particular value −
d.ContainsValue("Two");
The following is the complete code −
Example
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"));
}
}
Output
True
Advertisements
