ContainsKey(TKey)
suggest changeTo 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>.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents