DictionarymyDict = new Dictionary (); myDict.Add("apple", 1); myDict.Add("banana", 2); myDict.Add("orange", 3); bool containsValue = myDict.ContainsValue(2); // returns true
DictionaryIn this example, we create a dictionary with key-value pairs consisting of integers and strings. We then use the ContainsValue method to check if the value "Jane" is present in the dictionary. It returns false since this value is not present in the dictionary. The package library used in these examples is the System.Collections namespace.myDict = new Dictionary (); myDict.Add(1, "John"); myDict.Add(2, "Mary"); myDict.Add(3, "Bob"); bool containsValue = myDict.ContainsValue("Jane"); // returns false