ExtensionMethod.NET Home of 818 C#, Visual Basic, F# and Javascript extension methods

IEnumerable.None

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

Source

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

Author: Entroper

Submitted on: 2 aug 2016

Language: C#

Type: IEnumerable

Views: 1826