FirstOrDefault()

A LINQ operation returning the first item, or the type's default value when none exists.

What does FirstOrDefault() do in C#?

FirstOrDefault() — A LINQ operation returning the first item, or the type's default value when none exists.

class NameFinder
{
    string? First(IEnumerable<string> names)
    {
        return names.FirstOrDefault();
    }
}

Level: Freelancer · More C# terms at this level

Updated