求助,我这个代码哪里错了
string[] name ={"景珍","林惠阳","成蓉","洪南昌","龙玉民","单江开","田武山","王三明"};
int[] score ={90,65,88,70,46,81,100,68};
int sum=0,avg;
foreach(int i in score){
sum+=sum[i];
}
avg=sum/score.Length;
Console.WriteLine("平均分是"+avg,"高于平均分的有:");
for(int x=0; x<score.Length; x++){
if(score [x]>avg){
Console.Write(name[x]+" ");
}
}
是sum+=score[i]把
sum+=i;
而且你用foreach
int i in score
sum+=score[i]
是相当于i=90.i=65这样
超出了数组的界限了