請大佬解惑!
?string[] name={"吳松","錢東寧","伏晨","陳陸","周蕊","林日鵬","何昆","關欣"};
? ? ? ? ?int[] score=new int[]{89,90,98,56,60,91,93,85};
? ? ? ? ?int max=score[0];
? ? ? ? ?int k=0;
? ? ? ? ?for(int i=0;i<score.Length;i++)
? ? ? ? ?if(score[i]>max)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? max=score[i];
? ? ? ? ? ? ? ? k=i;
? ? ? ? ? ? }
? ? ? ? Console.Write("分數最高的是{0},分數是{1}",name[k],score[i]);
這個最后輸出score[i]為啥就程序錯誤呢,我知道填max就可以,但是請問下大佬填了score[i]錯誤在哪里!
2019-10-06
i是你循環里的臨時變量,循環完了i就被釋放了
2019-09-27
score[k]