Hashtable — how do you check if a specific state name (key) like "Kerala" exists in the table of state→capital entries?

Difficulty: Easy

Correct Answer: t.ContainsKey("Kerala")

Explanation:


Introduction / Context:
Hashtable stores key/value pairs. Efficient membership checks rely on keys, not values.



Concept / Approach:
Use ContainsKey to test the presence of a key. Use ContainsValue to search values (less efficient and not appropriate for checking key membership).



Why Other Options Are Wrong:
HasValue/HasKey/ContainsState are not Hashtable methods; ContainsValue checks values, not keys.



Final Answer:
t.ContainsKey("Kerala")

Discussion & Comments

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