C# Collections: Which One to Use and When
A practical guide to the C# collection types: List, Dictionary, HashSet, Queue, Stack and friends, with their costs and when to pick each one.
A practical guide to the C# collection types: List, Dictionary, HashSet, Queue, Stack and friends, with their costs and when to pick each one.
How to add, find and remove items with the generic List, why it replaced ArrayList, and what to watch for when you maintain code that still uses ArrayList.
How to push, pop and peek with the generic Stack in C#, avoid the empty-stack exception with TryPop, and use a stack to check balanced brackets.
How to enqueue, dequeue and peek with the generic Queue in C#, when to use PriorityQueue or ConcurrentQueue instead, and how the legacy Queue class differs.
Store and look up key-value pairs with the generic Dictionary in C#, and what to know about the legacy Hashtable when you maintain older code.