Mid
From PDF
Collections
C# Collections
How do you check if a Dictionary contains a specific key or value?
Short answer: ContainsKey(key) – checks for key existence ContainsValue(value) – checks for value Example: dictionary.ContainsKey("Alice"); // true/false dictionary.ContainsValue(30); // true/false
Example code
ContainsKey(key) – checks for key existence ContainsValue(value) – checks for value Example: dictionary.ContainsKey("Alice"); // true/false
dictionary.ContainsValue(30); // true/false
Real-world example (ShopNest)
ShopNest caches product prices in a Dictionary<string, decimal> keyed by SKU so checkout can look up a price in O(1) instead of scanning a list.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png