Valerie Meunier

Valerie Meunier

  • NA
  • 693
  • 82.8k

Error when no even elements in the array

Jun 18 2021 10:51 AM

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)