- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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