METHOD
Enumerable.FirstOrDefault
Returns first match or a supplied fallback in this overload.
Formal Syntax & Structure
csharp syntaxcsharp
source.FirstOrDefault(predicate, defaultValue)Working Example
Example Snippetcsharp
using System;using System.Linq;int n = new[] {1,2}.FirstOrDefault(x => x > 5, -1);