All
The All
method is useful when you need to verify that all elements in a list satisfy a particular boolean condition. If they all meet the specified condition the All
method will return true
, otherwise, it will return false
.
Basic example
Here we use All
operator to ensure that all the numbers in the array are positive.
Live example: https://dotnetfiddle.net/kofvbq
var scores = new[] { 87, 56, 33, 20, 11 };
var all = scores.All(i => i > 0); // check if all values are greater than zero
// output: true