dec*_*one 13
array.Skip(2).Take(5).Min();
Run Code Online (Sandbox Code Playgroud)
我想我也可以加入我的tuppence.由于Jason反对这样一个事实,即我们说的是跳过了多少而不是结束索引,我们可以添加一个简单的扩展方法:
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);
}
Run Code Online (Sandbox Code Playgroud)
然后:
int min = array.WithIndexBetween(2, 7).Min();
Run Code Online (Sandbox Code Playgroud)
调整扩展方法名称以尝试.(命名很难,而且我不会花很多时间在这里找到一个好的:)