Is there an equivalent of “None()” in LINQ?

前端 未结 3 1353
天涯浪人
天涯浪人 2021-02-06 23:19

I\'ve been running into situations where I feel I\'m lacking a LINQ extension method which effectivelly checks if there is no match of the specified predicate in a collection. T

3条回答
  •  甜味超标
    2021-02-06 23:43

    Even shorter version

    static class LinqExtensions
    {
        public static bool None(this IEnumerable source, Func predicate) => !source.Any(predicate);
    }
    

提交回复
热议问题