C# | Check if the StringDictionary contains a specific value Last Updated : 01 Feb, 2019 Comments Improve Suggest changes Like Article Like Report StringDictionary.ContainsValue(String) method is used to check whether the StringDictionary contains a specific value or not. Syntax: public virtual bool ContainsValue (string value); Here, value is the value to locate in the StringDictionary. The value can be null. Return Value: The method returns true if the StringDictionary contains an element with the specified value, otherwise it returns false. Below programs illustrate the use of StringDictionary.ContainsValue(String) method: Example 1: CSHARP // C# code to check if the // StringDictionary contains // a specific value using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // Creating a StringDictionary named myDict StringDictionary myDict = new StringDictionary(); // Adding key and value into the StringDictionary myDict.Add("G", "Geeks"); myDict.Add("F", "For"); myDict.Add("C", "C++"); myDict.Add("DS", "Data Structures"); myDict.Add("N", "Noida"); // Checking if "C++" is contained in // StringDictionary myDict if (myDict.ContainsValue("C++")) Console.WriteLine("StringDictionary myDict contains the value"); else Console.WriteLine("StringDictionary myDict does not contain the value"); } } Output: StringDictionary myDict contains the value Example 2: CSHARP // C# code to check if the // StringDictionary contains // a specific value using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // Creating a StringDictionary named myDict StringDictionary myDict = new StringDictionary(); // Adding key and value into the StringDictionary myDict.Add("G", "Geeks"); myDict.Add("F", "For"); myDict.Add("C", "C++"); myDict.Add("DS", "Data Structures"); myDict.Add("N", "Noida"); // Checking if "null" is contained in // StringDictionary myDict // It should not raise any exception if (myDict.ContainsValue(null)) Console.WriteLine("StringDictionary myDict contains the value"); else Console.WriteLine("StringDictionary myDict does not contain the value"); } } Output: StringDictionary myDict does not contain the value Note: The values of the elements of the StringDictionary are compared to the specified value using the Object.Equals method. This method is an O(n) operation, where n is Count. Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.specialized.stringdictionary.containsvalue?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Check if the StringDictionary contains a specific value S Sahil_Bansall Follow Improve Article Tags : C# CSharp-method CSharp-Collections-Namespace CSharp-Specialized-StringDictionary CSharp-Specialized-Namespace +1 More Similar Reads C# | Check if the StringDictionary contains a specific key StringDictionary.ContainsKey(String) method is used to check whether the StringDictionary contains a specific key or not. Syntax: public virtual bool ContainsKey (string key); Here, key is the key to locate in the StringDictionary. Return Value: This method returns true if the StringDictionary conta 2 min read C# | Check if the Hashtable contains a specific Value The Hashtable class represents a collection of key-and-value pairs that are organized based on the hash code of the key. The key is used to access the items in the collection. Hashtable.ContainsValue(Object) Method is used to check whether the Hashtable contains a specific value or not. Syntax: publ 2 min read C# | Get a collection of values in the StringDictionary StringDictionary.Values property is used to get a collection of values in the StringDictionary. Syntax: public virtual System.Collections.ICollection Values { get; } Return Value: An ICollection that provides the values in the StringDictionary. Example 1: CSHARP // C# code to get a collection // of 2 min read C# | Gets or sets the value at the specified key in StringDictionary StringDictionary.Item[String] Property is used to get or set the value associated with the specified key. Syntax: public virtual string this[string key] { get; set; } Here, key is the Key of type System.String whose value is be to get or set. Return Value: This property returns the value associated 3 min read C# | Check if ListDictionary contains a specific key ListDictionary.Contains(Object) method is used to check whether the ListDictionary contains a specific key or not. Syntax: public bool Contains (object key); Here, key is the key to locate in the ListDictionary. Return Value: The method returns true if the ListDictionary contains an entry with the s 2 min read Like