Suppose:
Dictionary<Guid, MyClass> dict;
Is there any difference between
dict.Keys.Contains(key)
and
dict.ContainsKey(key)
I thought there was no difference, but I am not sure now.
These two methods are guaranteed to return the same true/false value.
According to reference implementation, dict.Keys.Contains(key) delegates to dict.ContainsKey(key):
bool ICollection<TKey>.Contains(TKey item){
return dictionary.ContainsKey(item);
}
This method is part of KeyCollection class. Its dictionary field refers to the Dictionary object that owns the KeyCollection returned by Keys property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With