That's right. There is no method in the Array-class or extension method in the Enumerable-class which returns all indexes for a given predicate. So here is one:
public static IEnumerable<int> FindIndexes<T>(this IEnumerable<T> items, Func<T, bool> predicate)
{
int index = 0;
foreach (T item in items)
{
if (predicate(item))
{
yield return index;
}
index++;
}
}
Here is your sample:
string[] stringArray = { "fg v1", "ws v2", "sw v3", "sfd v2" };
string value = "v2";
int[] allIndexes = stringArray.FindIndexes(s => s.Contains(value)).ToArray();
It uses deferred execution, so you don't need to consume all indexes if you don't want.