C# 14 · Collections and LINQ

Use a dictionary

Add and read values by key. TryGetValue avoids an exception for missing keys.

var ages = new Dictionary<string, int> { ["Ada"] = 36 };
if (ages.TryGetValue("Ada", out var age)) Console.WriteLine(age);

Official C# 14 documentation

More collections and linq commands

All collections and linq commands · C# 14 cheatsheet

Was this page helpful?