All
Returns true if the provided predicate function returns true for all elements in a collection, false otherwise.
- Use
IEnumerable.ToArray(),Array.TrueForAll()to test if all elements in the collection returntruebased on the predicate function,match. - Omit the predicate function,
match, to use the overload that checks if each value is different fromnullby default.
using System.Collections.Generic;
using System.Linq;
public static partial class _30s
{
public static bool All<T>(IEnumerable<T> data, Predicate<T> match)
{
return Array.TrueForAll(data.ToArray(), match);
}
public static bool All<T>(IEnumerable<T> data)
{
return Array.TrueForAll(data.ToArray(), val => val != null);
}
}