Checks whether an enumeration contains at least a certain number of items. - CSharp System.Collections

CSharp examples for System.Collections:IEnumerable

Description

Checks whether an enumeration contains at least a certain number of items.

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*  www .  j  a  v a 2 s .  c  o  m*/

public class Main{
        /// <summary>
        /// Checks whether an enumeration contains at least a certain number of items.
        /// </summary>
        public static bool ContainsAtLeast<T>(this IEnumerable<T> enumeration, int count)
        {
            // Check to see that enumeration is not null
            if (enumeration == null)
                throw new ArgumentNullException("enumeration");

            return (from t in enumeration.Take(count)
                    select t)
                    .Count() == count;
        }
}

Related Tutorials