111,097
社区成员




var array=new int[]{1,3,5,6,7,8,9};
//1
var sum=array.Skip(minindex).Take(maxindex-minindex).Sum();
//2
var idx=array.Select((item, index)=>new{item,index}).FirstOrDefault(f=>f.item==value);
var ridx=idx==null??-1:idx;
var array = Enumerable.Range(1, 100).ToArray();
int index1 = 3, index2 = 5;
var sum = array.Skip(index1).Take(index2 - index1 + 1).Sum();
int value = 50;
var index = Array.IndexOf(array, value);
if( a < b) return -1; // index error
int sum = 0;
for(int i = a; i <=b; ++i)
sum += arr[i];
return sum;