.NET Framework First (find)

Download .NET Framework for free

Example

var numbers = new[] {1,2,3,4,5};

var firstNumber = numbers.First();
Console.WriteLine(firstNumber); //1

var firstEvenNumber = numbers.First(n => (n & 1) == 0);
Console.WriteLine(firstEvenNumber); //2

The following throws InvalidOperationException with message "Sequence contains no matching element":

var firstNegativeNumber = numbers.First(n => n < 0);
FirstOrDefault