Hashtable nullability rule — can a key be null and can a value be null?

Difficulty: Easy

Correct Answer: True — a key cannot be null, but a value can be null.

Explanation:


Introduction / Context:
Hashtable stores key/value pairs with hashing semantics. Null handling differs for keys and values.



Concept / Approach:
Hashtable prohibits null keys because hashing and equality logic require a valid object reference. However, values may legitimately be null to represent “no value” while still reserving a key in the table.



Why Other Options Are Wrong:
Allowing a null key breaks hashing; disallowing null values is unnecessary; the comparer does not change the prohibition on null keys.



Final Answer:
True — a key cannot be null, but a value can be null.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion