.NET developer

Stage 2 · Lesson 1 of 6

Collections and when to use each

C# for real work: LINQ, collections, generics and async

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

Practise

  • Keep going on the C# track: the later exercises lean on LINQ, generics and dictionaries

  • Solve easy array and hash map problems in C# to make collections and LINQ automatic

Keep handy

  • Return to the official C# modules on collections, LINQ and async when something is unclear

Also worth your time

Mark this stage as not done?