using System;
using System.Collections.Generic;
public static class Extensions // Make a static and non-generic class
{
public static IEnumerable<int> IndexesWhere<T>(this IEnumerable<T> source, Func<T, bool> predicate) {
int index = 0;
foreach (T element in source) {
if (predicate(element)) {
yield return index;
}
index++;
}
}
}
public class Program
{
public static void Main()
{
string[] s = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
"nine", "ten", "let\’s start again" };
var indexes = s.IndexesWhere(t => t.StartsWith("t"));
Console.Write(string.Join(", ", indexes));
}
}
/*
run:
2, 3, 10
*/