1 Star 0 Fork 0

woo/windows

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
C#作业二 1.31 KB
一键复制 编辑 原始数据 按行查看 历史
woo 提交于 2023-03-20 15:26 . rename C# to C#作业二.
public class Student : IComparable
{
public double mygrade;
public string mysubject, myID;
public Student() { }
public Student(double grade, string subject, string id)
{
mygrade = grade;
mysubject = subject;
myID = id;
}
int IComparable.CompareTo(Object obj)
{
if (obj is Student)
{
Student castObj = (Student)obj;
if (this.mygrade > castObj.mygrade) return 1;
else if (this.mygrade < castObj.mygrade) return -1;
else return 0;
}
throw new ArgumentException("object is not a Student");
}
}
internal class Program
{
private static void Main(string[] args)
{
Student[] students = new Student[5];
students[0] = new Student(50.0, "windows程序设计", "001");
students[1] = new Student(90.0, "windows程序设计", "002");
students[2] = new Student(100.0, "windows程序设计", "003");
students[3] = new Student(70.0, "windows程序设计", "004");
students[4] = new Student(80.0, "windows程序设计", "005");
Array.Sort(students);
foreach (Student student in students)
{
Console.WriteLine(student.mygrade + " " +student.mysubject + " " + student.myID);
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/GALI_5906/windows.git
git@gitee.com:GALI_5906/windows.git
GALI_5906
windows
windows
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385