C# Tutorial: Lists and Collections
List<T>, Dictionary<K,V>, HashSet<T> — C#'s generic collections.
Generic collections
Unlike arrays, `List<T>` can grow and shrink. It is the most commonly used collection in C#.
`Dictionary<K,V>` maps keys to values. `HashSet<T>` stores unique values.
What you'll learn in this C# lists and collections tutorial
This interactive C# tutorial has 8 hands-on exercises. Estimated time: 18 minutes.
- List<T> — `List<T>` is a resizable array. Use `Add`, `Remove`, and index access.
- List methods — Lists have many useful methods.
- List with foreach — Iterate a List with foreach.
- Dictionary<K,V> — `Dictionary<K,V>` maps keys to values.
- Iterate a Dictionary — Iterate with foreach to get KeyValuePair items.
- TryGetValue — `TryGetValue` safely gets a value without throwing on missing keys.
- HashSet<T> — `HashSet<T>` stores unique values with fast membership testing.
- Queue and Stack — `Queue<T>` is FIFO. `Stack<T>` is LIFO.
C# Lists and Collections concepts covered
- Generic collections