CKTIS / C#
Enumerable.All: practical reference
Enumerable.All: practical reference: Immediately tests the predicate and stops at the first element that returns false. It returns true only when every element read satisfies the condition.
Version: .NET LINQ; verified on .NET 10.0.14
Syntax
source.All(/* overload-specific arguments */)Immediately tests the predicate and stops at the first element that returns false. It returns true only when every element read satisfies the condition.
Use it to validate an entire set when one Boolean answer is needed and processing may stop after the first failure.
The predicate is not called for elements after the first false. Do not put logic in it that must run for the whole sequence.
For an empty sequence the result is true by universal-quantifier semantics; a null source or predicate causes ArgumentNullException.
The complete program actually uses Enumerable.All; its exact expected stdout is True.
Examples
using System;
using System.Collections.Generic;
using System.Linq;
Console.WriteLine(new[] { 2, 4, 6 }.All(value => value % 2 == 0));
Result
True
The complete program actually uses `Enumerable.All`; its exact expected stdout is `True`.