Student[] stuent = new Student[8]; stuent[0] = new Student { Name = "吴松",Grades = 89 }; stuent[1] = new Student { Name = "钱东宇", Grades = 90 }; stuent[2] = new Student { Name = "伏晨", Grades = 98 }; stuent[3] = new Student { Name = "陈陆", Grades = 56 }; stuent[4] = new Student { Name = "周蕊", Grades = 60 }; stuent[5] = new Student { Name = "林日鹏", Grades = 91 }; stuent[6] = new Student { Name = "何昆", Grades = 93 }; stuent[7] = new Student { Name = "关欣", Grades = 85 }; Student temp; for (int i = 0; i < stuent.Length - 1 ; i++) { for (int j = 0; j < stuent.Length - 1 - i; j++) { if (stuent[j].Grades < stuent[j + 1].Grades) { temp = stuent[j + 1]; stuent[j + 1] = stuent[j]; stuent[j] = temp; } } } /*for (int i = 0; i < 8; i++) { Console.WriteLine($"姓名{stuent[i].Name},分数:{stuent[i].Grades}"); }*/ Console.WriteLine($"分数最高的是{stuent[0].Name}"); } struct Student { private string name; private int grades; public string Name { get => name; set => name = value; } public int Grades { get => grades; set => grades = value; } /*public override string ToString() { return string.Format($"姓名:{this.Name},成绩:{this.Grades}"); }*/ }
string[] name=new string[8]
{"吴松","钱东宇","伏晨","陈陆","周蕊","林日鹏","何昆","关欣"};
int[] score =new int[8]{99,90,98,56,60,91,93,85};
int max = score[0];
int j = 0;
for(int i=0;i<score.Length;i++)
{
if(score[i]>max)
{
max=score[i];
j=i;
}
}
Console.WriteLine("最高分数的是:{0},分数是:{1}",name[j],max);