using System.Collections.Generic;
public static void Main()
var lst1 = new List<int>() { 1, 2, 1, 3, 4, 1 };
Console.WriteLine("Match 1");
lst1.FindEveryIndex(x => x == 1).Dump();
Console.WriteLine("Match 2");
lst1.FindEveryIndex(x => x == 2).Dump();
Console.WriteLine("Match 9");
lst1.FindEveryIndex(x => x == 9).Dump();
var lst2 = new List<string>() { "A", "B", "A", "C", "D", "A"};
Console.WriteLine("Match A");
lst2.FindEveryIndex(x => x=="A").Dump();
Console.WriteLine("Match B");
lst2.FindEveryIndex(x => x=="B").Dump();
Console.WriteLine("Match X");
lst2.FindEveryIndex(x => x=="X").Dump();
public static class Exttension
public static IEnumerable<int> FindEveryIndex<T>(this IEnumerable<T> items, Predicate<T> predicate)
int index = 0; bool found = false;
foreach (var item in items)
found = true; yield return index;
if (!found) yield return -1;