LearnThatStack Ace your next interview
C# · question
Question 14 of 112

What are the different types of generic collections in C#?

beginner
← All C# questions
Re-explain

The core generic collections are List<T>, Dictionary<TKey, TValue> and HashSet<T>, with queues, stacks and sorted versions for special cases. They live in System.Collections.Generic, are type-safe, and store value types without boxing.

  • List<T> is a dynamic array, and LinkedList<T> is a doubly linked list.
  • HashSet<T> holds unique items with fast lookup, and SortedSet<T> keeps them sorted.
  • Dictionary<TKey, TValue> maps keys to values with fast lookup, and SortedDictionary<TKey, TValue> keeps the keys sorted.
  • Queue<T> is first in, first out, and Stack<T> is last in, first out.

For shared access across threads, ConcurrentDictionary<TKey, TValue> in System.Collections.Concurrent is the thread-safe dictionary.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens How interviewers actually use this question

Likely follow-ups

  • You check membership often in a large collection. Would you use List<T> or HashSet<T>, and why? List<T>.Contains scans every item, while HashSet<T> uses the hash for near constant-time lookup. Note that HashSet drops duplicates and has no index.
  • What do you pay for SortedDictionary<TKey, TValue> compared with Dictionary<TKey, TValue>? Dictionary is a hash table with fast average lookup and no key order. SortedDictionary is a tree, so lookups are O(log n) but the keys stay in order.
  • What does a custom class need to work correctly as a Dictionary key? Equals and GetHashCode overrides that agree, or an IEqualityComparer<T>, plus key fields that don't change while the object is stored.
  • Is List<T> safe when several threads add to it at once? What would you use instead? Concurrent reads with no writer are fine, but writes are not. Name a lock, or a System.Collections.Concurrent type such as ConcurrentDictionary<TKey, TValue>.
  • How is List<T> different from the older ArrayList? ArrayList stores object, so reads need a cast and value types get boxed. List<T> checks types at compile time and stores ints directly.

What you can say

  1. The main generic collections are List<T>, Dictionary<TKey, TValue> and HashSet<T>, and I use queues, stacks and the sorted versions when I need their specific behavior.
  2. They all live in System.Collections.Generic and they're type-safe, so a List<int> stores ints directly, without boxing.
  3. List<T> is a dynamic array and my default choice, and LinkedList<T> is a doubly linked list.
  4. HashSet<T> holds unique items and Dictionary<TKey, TValue> maps keys to values, both with fast lookup, and SortedSet<T> and SortedDictionary keep things in sorted order.
  5. Queue<T> is first in, first out, and Stack<T> is last in, first out.
  6. The standard ones aren't safe for shared writes across threads, so for that I'd use ConcurrentDictionary<TKey, TValue> from System.Collections.Concurrent.

Weak answers to avoid

  • Lists type names with no use case A list of names only shows you memorized them. Tie each one to its job, like key lookup, unique items, or FIFO and LIFO order.
  • Mixes in non-generic ArrayList and Hashtable Those live in System.Collections and store object, so they box value types. Call them legacy and say List<T> and Dictionary<TKey, TValue> replaced them.
  • Calls Dictionary ordered or thread-safe Dictionary promises no order and isn't safe for concurrent writes. Point to SortedDictionary for order and ConcurrentDictionary for threads.
  • Says List<T> is a linked list List<T> wraps a resizable array, so index access is fast and inserts in the middle shift items. LinkedList<T> is the doubly linked list.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the C# cheatsheet.

← Back to all C# questions
Pro · $10/mo

98 of 112 C# answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime