The predicate returns false to stop the iteration. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IEnumerable

Description

The predicate returns false to stop the iteration.

Demo Code


using System.Reflection;
using System.Linq;
using System.Collections.Generic;
using System;/*  w  w  w .  j av a2 s .  c om*/

public class Main{
        /// <summary>
      /// The predicate returns false to stop the iteration (and to indicate that it found the item).
      /// Iterate returns true once the predicate returned false the first time.
      /// </summary>
      public static bool Iterate<T>(this IEnumerable<T> items, Func<T, bool> predicate)
      {
         foreach (var item in items)
         {
            if (!predicate(item))
            {
               return true;
            }
         }
         return false;
      }
}

Related Tutorials