提交后只出現景珍,提示索引超出數值接線,有大佬回答嗎
namespace projAboveAvg
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ?string[,] score={{"景珍","90"},{"林惠洋","65"},{"成蓉","88"},{"洪南昌","70"},{"龍玉民","46"},{"單江開","81"},{"田武山","100"},{"王三明","68"}};
? ? ? ? ? ?int sum=0,avg;
? ? ? ? ? ?for(int i=0;i<score.GetLongLength(0);i++)
? ? ? ? ? ?{
? ? ? ? ? ? ? ?sum +=int.Parse(score[i,1]);
? ? ? ? ? ?}
? ? ? ? ? ?avg=sum/score.GetLength(0);
? ? ? ? ? ? ? ?Console.WriteLine("平均分是{0},高于平均分的有:",avg);
? ? ? ? ? ?for(int x=0;x<score.GetLongLength(0);x++)
? ? ? ? ? ?{
? ? ? ? ? ? ? ?if(int.Parse(score[x,1])> avg)
? ? ? ? ? ? ? ? ? Console.Write(score[0,x]+" ");
? ? ? ? ? ?}
? ? ? ? }
? ? }
}
2019-09-09
Console.Write(score[0,x]+" ");
二維數組的上標超了,應該改為Console.Write(score[x,0]+" ");