Why doesn't HashTable.Contains() just simply return false if it is passed a null?
Posted
by Nate Pinchot
on Stack Overflow
See other posts from Stack Overflow
or by Nate Pinchot
Published on 2010-06-16T13:35:11Z
Indexed on
2010/06/16
13:42 UTC
Read the original article
Hit count: 194
I understand why passing a null to HashTable.Contains() doesn't work, but I don't understand what the point of it throwing an ArgumentNullException
is - instead of just simply returning false
? What is the benefit of throwing the exception (other than to make me do null checks before calling .Contains()
)?
Caused By [System.ArgumentNullException]
Key cannot be null.
Parameter name: key
at System.Collections.Hashtable.ContainsKey(Object key)
at System.Collections.Hashtable.Contains(Object key)
© Stack Overflow or respective owner