Index Of IEnumerable - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IEnumerable

Description

Index Of IEnumerable

Demo Code

// Permission is hereby granted, free of charge, to any person
using System.Globalization;
using System.Linq;
using System.Collections;
using System.Text;
using System.Reflection;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System;//from  www .  j a v  a 2 s  . c  o m

public class Main{
    public static int IndexOf<T>(this IEnumerable<T> collection, Func<T, bool> predicate)
    {
      int index = 0;
      foreach (T value in collection)
      {
        if (predicate(value))
          return index;

        index++;
      }

      return -1;
    }
}

Related Tutorials