IndicesOf

public static IEnumerable<int> IndicesOf<T>(this IEnumerable<T> obj, T value)
{
    return (from i in Enumerable.Range(0, obj.Count())
            where obj.ElementAt(i).Equals(value)
            select i);
}

public static IEnumerable<int> IndicesOf<T>(this IEnumerable<T> obj, IEnumerable<T> value)
{
    return (from i in Enumerable.Range(0, obj.Count())
            where value.Contains(obj.ElementAt(i))
            select i);
}
Example:
var t = new Collection<int> { 0,1,2,3,1,1,3,4 };

var first = t.IndicesOf(3);
//returns 3,6
var second = t.IndicesOf(new int[]{0,3});
//returns 0,3,6

Description

Finds all the indexes of the give value or values in an enumerable list

Details

Double click on the code to select all.

 

;