linq中的All

相关源码:

public static bool All<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) {
            if (source == null) throw Error.ArgumentNull("source");
            if (predicate == null) throw Error.ArgumentNull("predicate");
            foreach (TSource element in source) {
                if (!predicate(element)) return false;
            }
            return true;
}

判断Enumerable集合中的元素是否都符合条件。

string[] strs = "d|fd|dd|sd|fd|sd|ad|d|d|d|ad|fd|d|gd|d|fd".Split('|');
bool isTure = strs.All(s => s.EndsWith("d"));//true

这个好像没有什么可以特殊使用的地方。

posted @ 2021-11-15 14:20  vba是最好的语言  阅读(43)  评论(0编辑  收藏  举报