Programming foundations

Stage 1 · Lesson 6 of 9

List<T>, Dictionary<TKey, TValue> and HashSet<T>

Your first language

C# have a fixed length, so most code uses the generic collections instead. A List<string> grows as you Add items, and has Count, , Remove and Contains. A , such as Dictionary<string, int>, maps keys to values.

dict["bob"] throws KeyNotFoundException when the key is missing, so use TryGetValue or GetValueOrDefault to check first. A stores unique items and makes "is this in here?" checks fast. The type in angle brackets is a generic parameter: it tells the compiler what the collection holds, so it stops you adding the wrong thing.

Collection initialisers such as new List<int> { 1, 2, 3 } keep setup short. LINQ methods such as Where and Select can wait until feel natural.

A question to check yourself, an AI practice session and 3 cheat sheet entries come when you add the roadmap to your account. Add it

Resources for this stage

Start with· follow one of these

  • GuideFree
    Learn C#

    Microsoft · Beginner

    Official C# fundamentals tutorials that you run locally with the .NET SDK

  • PlatformFree
    freeCodeCamp

    freeCodeCamp · Beginner

    Free Foundational C# certification, built with Microsoft, with a graded exam at the end

Practise

  • Small exercises in your language track, with free feedback from a human mentor

Keep handy

  • Quick C# syntax lookups with a try-it editor; not a replacement for the course

Mark this stage as not done?