<Member Name="get_Keys" />
<Member Name="get_Values" />
<Member Name="GetEnumerator" />
+ <Member Name="GetValueOrDefault(TKey)" />
+ <Member Name="GetValueOrDefault(TKey,TValue)" />
<Member Name="Remove(TKey)" />
<Member Name="set_Item(TKey,TValue)" />
<Member Name="TryGetValue(TKey,TValue@)" />
return false;
}
- // This is a convenience method for the internal callers that were converted from using Hashtable.
- // Many were combining key doesn't exist and key exists but null value (for non-value types) checks.
- // This allows them to continue getting that behavior with minimal code delta. This is basically
- // TryGetValue without the out param
- internal TValue GetValueOrDefault(TKey key) {
+ // Method similar to TryGetValue that returns the value instead of putting it in an out param.
+ public TValue GetValueOrDefault(TKey key) => GetValueOrDefault(key, default(TValue));
+
+ // Method similar to TryGetValue that returns the value instead of putting it in an out param. If the entry
+ // doesn't exist, returns the defaultValue instead.
+ public TValue GetValueOrDefault(TKey key, TValue defaultValue)
+ {
int i = FindEntry(key);
- if (i >= 0) {
+ if (i >= 0)
+ {
return entries[i].value;
}
- return default(TValue);
+ return defaultValue;
}
bool ICollection<KeyValuePair<TKey,TValue>>.IsReadOnly {