Is there an equivalent of "None()" in LINQ?
You can write your own Extension Method
:
public static bool None(this IEnumerable<T> collection, Func<T, bool> predicate)
{
return collection.All(p=>predicate(p)==false);
}
Or on IQueryable<T>
as well
public static bool None(this IQueryable<T> collection, Expression<Func<TSource, bool>> predicate)
{
return collection.All(p=> predicate(p)==false);
}
None
is the same as !Any
, so you could define your own extension method as follows:
public static class EnumerableExtensions
{
public static bool None<TSource>(this IEnumerable<TSource> source,
Func<TSource, bool> predicate)
{
return !source.Any(predicate);
}
}