C# | Dictionary.ContainsValue() Method Last Updated : 01 Feb, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report This method is used to check whether the Dictionary<TKey,TValue> contains a specific value or not. Syntax: public bool ContainsValue (TValue value); Here, the value is the Value to locate in the Dictionary. The value can be null for reference types. Return Value: This method returns true if the Dictionary contains an element with the specified value otherwise it returns false. Below are the programs to illustrate the use of Dictionary<TKey,TValue>.ContainsValue() Method: Example 1: csharp // C# code to check if a value // is present or not in a Dictionary. using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Create a new dictionary of // strings, with string keys. Dictionary<string, string> myDict = new Dictionary<string, string>(); // Adding key/value pairs in myDict myDict.Add("Australia", "Canberra"); myDict.Add("Belgium", "Brussels"); myDict.Add("Netherlands", "Amsterdam"); myDict.Add("China", "Beijing"); myDict.Add("Russia", "Moscow"); myDict.Add("India", "New Delhi"); // Checking the value "India" but // here "India" is the key if (myDict.ContainsValue("India")) Console.WriteLine("Value : India is present."); else Console.WriteLine("Value : India is not present."); } } Output: Value : India is not present. Example 2: csharp // C# code to check if a value is // present or not in a Dictionary. using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Create a new dictionary of // strings, with string keys. Dictionary<string, string> myDict = new Dictionary<string, string>(); // Adding key/value pairs in myDict myDict.Add("Australia", "Canberra"); myDict.Add("Belgium", "Brussels"); myDict.Add("Netherlands", "Amsterdam"); myDict.Add("China", "Beijing"); myDict.Add("Russia", "Moscow"); myDict.Add("India", "New Delhi"); // Checking for value Moscow if (myDict.ContainsValue("Moscow")) Console.WriteLine("Value : Moscow is present"); else Console.WriteLine("Value : Moscow is absent"); } } Output: Value : Moscow is present Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.containsvalue?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Dictionary.ContainsValue() Method R rupesh_rao Follow Improve Article Tags : C# CSharp-method CSharp-Generic-Namespace CSharp Dictionary Class Similar Reads C# | Dictionary.ContainsKey() Method This method is used to check whether the Dictionary<TKey,TValue> contains the specified key or not. Syntax: public bool ContainsKey (TKey key); Here, the key is the Key which is to be located in the Dictionary. Return Value: This method will return true if the Dictionary contains an element wi 2 min read C# | SortedDictionary.ContainsValue() Method This method is used to check whether the SortedDictionary<TKey, TValue> contains an element with the specified value or not. Syntax: public bool ContainsValue (TValue value); Here, the value is the Value to locate in the SortedDictionary. The value can be null for reference types. Return Value 2 min read Stack.Contains() Method in C# This method(comes under System.Collections namespace) is used to check whether a specified element is present is Stack or not. Internally this method checks for equality by calling the Object.Equals method. Also, it performs a linear search, therefore, this method is an O(n) operation, where n is Co 2 min read C# | Dictionary.Count Property This property is used to get the number of key/value pairs contained in the Dictionary. Syntax: public int Count { get; } Return Value : The number of key/value pairs contained in the Dictionary. Below are the programs to illustrate the use of above-discussed property: Example 1: csharp // C# code t 2 min read C# Dictionary Class In C#, the Dictionary class is the part of the System.Collections.Generic namespace. It is a Collection that stores Key-value pairs. Each key in the dictionary is unique and each key maps to a single value.In Dictionary, each entry consists of a key and its associated value.It provides constant time 7 min read Like