W3Teacher
  • Explore
    Browse by field
    Artificial Intelligence Accounting & Finance Information Technology
    Show all fields
  • Interview Q&A
    • All Interview Questions
    • Beginner
    • Intermediate
    • Advanced
  • Practice
    • MCQs
    • Quizzes
    • Mock Interviews
  • About
  • Sign in
  • Get Started
  1. Home
  2. Search: Collections
  3. C#
  4. Collections
  5. Question
All 16 Collections questions
More in Collections
When would you use a List<T> vs an array? What is the difference between List<T> and an array (T[]) in terms of resizing? What is the difference between Dictionary<TKey, TValue> and List<T> in terms of lookup performance? What is the difference between IEnumerable, ICollection and IList? What does HashSet<T> provide and when do you use it? When would you choose a HashSet<T> over a List<T>, and what guarantee does it provide? How does Queue<T> differ from Stack<T> in terms of the order items are removed? What is the difference between IEnumerable<T>, ICollection<T>, and IList<T> in the collection interface hierarchy? When would you reach for a ConcurrentDictionary or an immutable collection? How do you avoid multiple enumeration of an IEnumerable?
Advertisement
Back to results for “Collections”
C# › Collections

When should you use a Dictionary<TKey,TValue>?

Beginner

Answer

When you need fast key-based lookups (O(1) average). Keys are unique; use TryGetValue to avoid exceptions on missing keys.
var prices = new Dictionary<string,decimal>{["pen"]=1.5m};
if (prices.TryGetValue("pen", out var p)) { }
Real-world example Caching users by Id or counting word frequencies.
Previous question When would you use a List<T> vs an array? Next question What is the difference between List<T> and an array (T[]) in terms of resizing?
All 16 Collections questions
W3Teacher

Learn technologies. Ace technical interviews.


    Learn
    • Technologies
    • Tutorials
    • Interview Questions
    • MCQs
    Practice
    • Quizzes
    • Mock Interviews
    • Bookmarks
    • Dashboard
    Get the latest questions & tips

    Fresh interview questions and practice tips, straight to your inbox.

    Company
    • About
    • Contact us
    • Privacy Policy
    • Terms & Conditions

    © 2026 W3Teacher. All rights reserved.