Given such a list:
List intList = new List();
intList.Add(5);
intList.Add(10);
intList.Add(15);
public static class Extensions
{
public static int MaxIndex(this IEnumerable TSource)
{
int i = -1;
using (var iterator = TSource.GetEnumerator())
while (iterator.MoveNext())
i++;
return i;
}
}
Here is my crack at this problem. I returned -1 instead of throwing an exception because this is what the FindIndex function does and I find it very convenient.