True value in IEnumerable For All by Predicate - CSharp System.Collections

CSharp examples for System.Collections:IEnumerable

Description

True value in IEnumerable For All by Predicate

Demo Code


using System.Collections.Generic;
using System.Collections;
using System;/*from   w  w  w .ja  va2 s .c om*/

public class Main{
        internal static bool TrueForAll<T>(IEnumerable<T> collection, Predicate<T> predicate)
        {
            if (collection == null)
                throw new ArgumentNullException("collection");
            if (predicate == null)
                throw new ArgumentNullException("predicate");

            foreach (T item in collection) {
                if (!predicate(item))
                    return false;
            }

            return true;
        }
}

Related Tutorials