111,126
社区成员
发帖
与我相关
我的任务
分享using System;
using System.Collections;
struct student
{
public string no, name, sex;
public int age, score;
public student(string no, string name, int age, string sex, int score)
{
this.no = no;
this.name = name;
this.sex = sex;
this.age = age;
this.score = score;
}
}
class Program
{
static void Main()
{
student stu1 = new student("20070001", "王明", 20, "male", 89);
student stu2 = new student("20070002", "王铭", 19, "female", 92);
student stu3 = new student("20070003", "王鸣", 20, "male", 83);
student stu4 = new student("20070004", "王名", 21, "male", 66);
int[] a = new int[] {stu1.score,stu2.score,stu3.score,stu4.score};
student[] st = new student[] {stu1, stu2, stu3, stu4 };
Array.Sort(a, st);
foreach ( student s in st)
{
Console.WriteLine("{0} {1}", s.name, s.score);
}
}
}
/* 输出:
王名 66
王鸣 83
王明 89
王铭 92
*/