c# if dictionary contains key code example
Example 1: c# check to see if dictionary key exists
bool keyExists = dict.ContainsKey(key);
Example 2: c sharp check if key in dictionary
// To check if a dictionary has a certain key, use 'ContainsKey()'
dict.ContainsKey(key);
Example 3: if in dictionary c#
if (dict.ContainsKey(key)) { ... }
//or
dict.TryGetValue(key, out value);