ContainsKey(TKey)

suggest change

To check whether a Dictionary contains a specific key, call ContainsKey(TKey) and pass a key of type TKey. The method returns true when the key exists in the dictionary and false otherwise. For example:

var dictionary = new Dictionary<string, Customer>()
{
   {"F1", new Customer() { FirstName = "Felipe", ... } },
   {"C2", new Customer() { FirstName = "Carl", ... } },
   {"J7", new Customer() { FirstName = "John", ... } },
   {"M5", new Customer() { FirstName = "Mary", ... } },
};

Check whether C2 exists in the dictionary:

if (dictionary.ContainsKey("C2")) 
{
   // exists
}

ContainsKey is a method of the generic Dictionary<TKey, TValue>.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents