You can have a class that implements IEnumerable and returns the indices you want:
public class Traverse<T> : IEnumerable<int>
{
T[] _list;
T _value;
public Traverse(T[] list, T value)
{
this._list = list;
this._value = value;
}
public IEnumerator<int> GetEnumerator()
{
for (int i = 0; i < _list.Length; i++)
if (_list[i].Equals(_value))
yield return i;
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
And use it like this:
int[] arr = { 3, 5, 6, 7, 2, 3, 11, 14 };
foreach (var index in new Traverse<int>(arr, 3))
Console.WriteLine(index.ToString());
output:
0
5