Tsallaka zuwa abun ciki
Justice Tech School

C# Dictionaries

Dictionary<K,V> stores key value pairs with fast lookup by key. TryGetValue checks safely. HashSet<T> stores unique values.

Example
var ages = new Dictionary<string, int> { ["Ada"] = 21, ["Tunde"] = 30 };
ages["Zainab"] = 25;
if (ages.TryGetValue("Ada", out int a)) Console.WriteLine(a);
foreach (var (k, v) in ages) Console.WriteLine($"{k}={v}");
var set = new HashSet<int> { 1, 2, 2, 3 };
Console.WriteLine(set.Count);

Exercise

Safe lookup method.

dict.(key, out v)

Quiz Test

What does a HashSet keep?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.