ConcurrentDictionarydict = new ConcurrentDictionary (); dict.TryAdd(1, "apple"); dict.TryAdd(2, "banana"); dict.TryAdd(3, "orange"); bool containsKey = dict.Contains(1); // returns true bool containsKey2 = dict.Contains(4); // returns false
ConcurrentDictionaryIn this example, we create a new ConcurrentDictionary instance and add some key-value pairs to it. We then check if the dictionary contains the value "apple" and "grape" using the ContainsValue method. Package/Library: System.Collections.Concurrentdict = new ConcurrentDictionary (); dict.TryAdd(1, "apple"); dict.TryAdd(2, "banana"); dict.TryAdd(3, "orange"); bool containsValue = dict.ContainsValue("apple"); // returns true bool containsValue2 = dict.ContainsValue("grape"); // returns false