Полагаю, я тоже могу добавить к этому свое терпение. Поскольку Джейсон возражает против того, что мы говорим, сколько мы пропускаем, а не конечный индекс, мы можем добавить простой метод расширения:
public static IEnumerable<T> WithIndexBetween<T>(this IEnumerable<T> source,
int startInclusive, int endExclusive)
{
// The two values can be the same, yielding no results... but they must
// indicate a reasonable range
if (endExclusive < startInclusive)
{
throw new ArgumentOutOfRangeException("endExclusive");
}
return source.Skip(startInclusive).Take(endExclusive - startInclusive);
}
Тогда:
int min = array.WithIndexBetween(2, 7).Min();
Настройте имя метода расширения по вкусу. (Назвать сложно, и я не собираюсь целую вечность придумывать хороший здесь:)