var numbers = new[] {1,2,3,4,5};
var lastNumber = numbers.Last();
Console.WriteLine(lastNumber); //5
var lastEvenNumber = numbers.Last(n => (n & 1) == 0);
Console.WriteLine(lastEvenNumber); //4
The following throws InvalidOperationException
:
var lastNegativeNumber = numbers.Last(n => n < 0);