Hashtable — how do you check if a specific state name (key) like "Kerala" exists in the table of state→capital entries?
C# Programming
Collection Classes
Difficulty: Easy
Choose an option
-
At.ContainsKey("Kerala")
-
Bt.HasValue("Kerala")
-
Ct.HasKey("Kerala")
-
Dt.ContainsState("Kerala")
-
Et.ContainsValue("Kerala")
Answer
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")