0Pricing
C# Academy · Lesson

Choosing a Collection

Trade-offs and performance.

One Question First

Choosing a collection starts with one question: how will you access the data? By position, by key, or just check membership?

List, Dictionary, and HashSet each answer a different access pattern. Match the tool to the pattern and your code stays fast and clear.

Access by Position: List

If order matters and you reach items by index, choose List<T>. It keeps insertion order and gives O(1) indexing.

Examples: a queue of steps, rows in display order, or any sequence you iterate front to back. Duplicates are allowed.

var steps = new List<string> { "mix", "bake", "cool" };
string first = steps[0]; // O(1) by index

All lessons in this course

  1. List in Practice
  2. Dictionary Lookups
  3. HashSet and Uniqueness
  4. Choosing a Collection
← Back to C# Academy