All
suggest changeAll checks whether every element of a collection matches a condition. See also: .Any
1. Empty parameter
All cannot be called without a predicate.
2. Lambda expression as parameter
All returns true if every element of the collection satisfies the lambda expression, and false otherwise:
var numbers = new List<int>(){ 1, 2, 3, 4, 5};
bool result = numbers.All(i => i < 10); // true
result = numbers.All(i => i >= 3); // false
3. Empty collection
All returns true if the collection is empty and a lambda expression is supplied:
var numbers = new List<int>();
bool result = numbers.All(i => i >= 0); // true
Note: All will stop iteration of the collection as soon as it finds an element not matching the condition. This means that the collection will not necessarily be fully enumerated; it will only be enumerated far enough to find the first item not matching the condition.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents