Introduction
The “All” operator is a quantifier operator in LINQ used to check if each element from the collection satisfies a given condition or not. If the condition is satisfied for each element within the collection, the outcome of the operator is true. Otherwise, the outcome is false
The evaluation condition must be mandatory to return a Boolean outcome. In other words: The result of the condition has to be True or False.
API Details
Example
IPO | Samples | Comment |
---|---|---|
Values: | {2,5,17,9,13} | A collection of numbers |
Condition: | x < 10 | Check if all numbers in the collection are less than 10 |
Result: | False | the result obtained after applying the filter |
I – Input, P – Processing, O – Output
Implementation with Essential activities
A classic way of implementation with essential activities would be
- ForEach# |item | Values: arrNumbers | TypeArgument = Int32
- If#: item <10
- Then assign the boolean result to a hasFound variable.
- Stop the loop with a break activity
Result: hasFound Variable with True / False Value indicates if each item is matching the condition
Implementation with LINQ
Method Syntax
arrNumbersFiltered = arrNumbers.All(function (x) x < 10)
Every item from the collection is evaluated for the condition x < 10 where x represents the current checked item from an internal loop.
Query Syntax
The “All” operator is not available as a building block in the Query Syntax. But it can be combined with an appended All operator as method syntax. As a result, the strength of both can be utilized.
(From x In arrNumbers
Select x < 10).All(Function (b) b)
Samples
Data Table Example
Check in a data table if all column (“ColA”) values are not blank / empty
dtVar.AsEnumerable.All(Function (x) Not ( isNothing(x(“ColA”)) OrElse String.IsNullOrEmpty(x(“ColA”).ToString.Trim)))
Data Column Example
Check if no data column name ends with “_1”
dtVar.Columns.Cast(of DataColumn).ALL(Function (x) Not x.ColumnName.EndsWith(“_1”))
References
- tutorialsteacher LINQ Tutorials from Basics to Advanced
- linqsamples https://linqsamples.com
Recommendations
Questions
For questions on your retrieval case, open a new topic and get individual support