Check if IEnumerable Contains by condition - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IEnumerable

Description

Check if IEnumerable Contains by condition

Demo Code


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

public class Main{
    public static bool Contains<T>(this IEnumerable<T> list, Func<T, bool> predicate)
      {
         foreach (var item in list)
         {
            if (predicate(item))
            {
               return true;
            }
         }
         return false;
      }
}

Related Tutorials