IEnumerable.None

public static bool None<T>(this IEnumerable<T> collection) => !collection.Any();

public static bool None<T>(this IEnumerable<T> collection, Func<T, bool> predicate) => !collection.Any(predicate);
Example:
var intList = new List<int> { 1, 2, 3 };
var emptyList = new List<int>();

intList.None(); // false
emptyList.None(); // true

intList.None(i => i == 2); // false
intList.None(i => i > 5); // true

Description

The opposite of Any(). Returns true if the collection is empty, or if no item matches the predicate.

Details

Double click on the code to select all.

 

;