How to check if all the elements in an array are positive integers?

Posted by Niladri.Biswas under C# category on | Points: 40 | Views : 698
If you want to check whether everything is strictly positive, use:

bool allPositive = array.All(x => x > 0);

If you actually want to check they're all non-negative (i.e. 0 is acceptable) use:

bool allNonNegative = array.All(x => x >= 0);

Comments or Responses

Login to post response