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)
falsemeans that the hash table doesn’t contain the key supplied.There needs to be another way of indicating that you’ve supplied an invalid key.
You could always wrap
HashTable.Containsin another method that does the checking for null (or traps the exception) and returnsfalsein this case.