Stage 2 · Lesson 1 of 6
Collections and when to use each
Most code is moving data through collections, so choose them on purpose. List<T> keeps order and allows duplicates. Dictionary<TKey, TValue> finds a value by key in roughly constant time, which is right for lookups by account number.
HashSet<T> answers 'have I seen this?' quickly, which is right for spotting duplicate references. Queue<T> and Stack<T> give first-in-first-out and last-in-first-out. Arrays are fixed size.
For shared data across threads, use the System.Collections.Concurrent types or avoid sharing. Expose IReadOnlyList<T> from methods when callers should not change the list.
Common trapcalling list.Contains inside a loop over 100,000 items: that is 10 billion comparisons, while a does the same job in a blink.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking Data Structures & Algorithms for Coding Interviews
Design Gurus · Beginner · Subscription
Arrays, hash tables, lists, stacks and queues: what every C# collection is built on, with complexity explained
- GuideFree.NET documentation
Microsoft
Free official guides on LINQ, generics, collections and the asynchronous programming model