Lists and Dictionaries
Store ordered values and keyed data with generic collections.
Introduction
Generic collections preserve type safety and grow dynamically as the program runs.
List<T> maintains order. Dictionary<TKey,TValue> provides fast lookup and TryGetValue avoids exceptions for missing keys.
See how it works
Use the buttons to change the list and watch the indices update. Move start and stop to see which items a slice takes.
Runnable C# example
Program.cs
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
var scores = new Dictionary<string, int> { ["Ada"] = 95, ["Lin"] = 88 };
scores["Grace"] = 92;
if (scores.TryGetValue("Grace", out int score))
Console.WriteLine(score);
}
}
92Practice with the debugger
Set a breakpoint on an important assignment or condition, click Debug, and inspect the local values before stepping to the next line.
Practice with a challenge
Use what this lesson covers to solve a real problem. Each challenge runs in your browser with instant tests and an AI review.
- Character Frequency Count how often each character appears. Easy
- Remove Duplicates Keep only the first occurrence of each value. Easy