Time for action – how to check whether all items match a condition
Follow the given steps:
- Copy the following as a query to LINQPad:
int[] numbers = { 0, 2, 34, 22, 14 }; bool allEven = numbers.All(c => c % 2 == 0); string status = allEven? "All numbers are even":"All numbers are not even"; status.Dump("Status");
- Run the query and you should get the following output:
As all the elements in numbers
are even, allEven
will be set to true
.
Merging operators
In this section, we will discuss the following Merging operators:
Zip()
This operator lets us combine the values of several collections and project them in a single collection of type IEnumerable<T>
. This ...
Get .NET 4.0 Generics now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.