2
Answers

Error when no even elements in the array

Hi again,

This gives the max of even elements in an array:

Console.WriteLine("max even elements:" + myNumbers.Where(n => n % 2 == 0).Max());

But gives an error (InvalidOperation no elements ...) when there are no even elements in the array.

How to avoid that message? Thanks

Answers (2)