Lists and Dictionaries
Generic collections preserve type safety and grow dynamically as the program runs.
How it works
Store ordered values and keyed data with generic collections.
List<T> maintains order. Dictionary<TKey,TValue> provides fast lookup and TryGetValue avoids exceptions for missing keys.
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.