C# 14 · Collections and LINQ

Find or test elements

FirstOrDefault returns null or default when nothing matches, while First throws.

var admin = users.FirstOrDefault(u => u.IsAdmin);
bool any = users.Any(u => u.Age > 60);

Official C# 14 documentation

More collections and linq commands

All collections and linq commands · C# 14 cheatsheet

Was this page helpful?