METHOD
Enumerable.DefaultIfEmpty
Preserves a nonempty sequence; supplies one fallback element when it is empty. This is not a replacement for every default-valued element.
Formal Syntax & Structure
csharp syntaxcsharp
items.DefaultIfEmpty(fallback)Working Example
Example Snippetcsharp
using System;using System.Linq;Console.WriteLine(string.Join(",", Array.Empty<int>().DefaultIfEmpty(-1))); // -1