CSharp examples for System.Collections:IEnumerable
Find Index in IEnumerable by Predicate
using System.Text; using System.Linq; using System.Collections.Generic; using System;//from ww w . j av a2 s.c o m public class Main{ public static int FindIndex<T>(this IEnumerable<T> source, Predicate<T> predicate) { int index = 0; foreach (T elem in source) { if (predicate(elem)) { return index; } ++index; } return -1; } }