1 Star 0 Fork 51

杨杨/C_sharp面向对象笔记

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
集合与范类.txt 1.99 KB
一键复制 编辑 原始数据 按行查看 历史
蓝文龙 提交于 2022-05-09 07:56 . 作业
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
?using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Work1
{
// 1 乔峰 85 42 67
//2 段誉 94 34 46
//3 虚竹 99 99 99
class Student:IComparable
{
public int Id { get; set; }
public string Name { get; set; }
public double Chinese { get; set; }
public double Math { get; set; }
public double English { get; set; }
public Student ()
{
}
public Student(int id, string name, double chinese,double math,double english)
{
this.Id = id;
this.Name = name;
this.Chinese = chinese;
this.Math = math;
this.English = english;
}
//重写ToString方法,使输出对象时,可以是我们return的信息
public override string ToString()
{
return $"学号:{Id},姓名:{Name},语文成绩:{Chinese},数学成绩:{Math},英语成绩:{English}";
}
public int CompareTo(object obj)
{
//as判断对象是否是Student,是返回该对象,不是返回null
Student other = obj as Student;
//Id比较
//this.Id与other.id对比
if (other != null)
{
//根据学号排序
//return this.Id - other.Id;
//根据名字排序
//return string.Compare(this.Name,other.Name);
//根据成绩排序
//return (int)(other.Score - this.Score);
return (int)(other.English - this.English);
}
else
{
return 0;
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/GIT207706948/c-sharp-object-oriented-notes.git
git@gitee.com:GIT207706948/c-sharp-object-oriented-notes.git
GIT207706948
c-sharp-object-oriented-notes
C_sharp面向对象笔记
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385