Last

suggest change
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);

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents