CSharp examples for System.Collections.Generic:IEnumerable
Find Element from IEnumerable by Predicate
using System.Collections.Generic; using System.Collections; using System;/*from w w w. j av a 2s.com*/ public class Main{ public static T Find<T>(IEnumerable collection, Predicate<T> p) { foreach (T obj in collection) { if (p(obj)) return obj; } return default(T); } /// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="collection"></param> /// <param name="p"></param> /// <returns></returns> public static T Find<T>(IEnumerable<T> collection, Predicate<T> p) { foreach (T obj in collection) { if (p(obj)) return obj; } return default(T); } }