设为首页 加入收藏

TOP

比较和排序(IComparable和IComparer以及它们的泛型实现)(转)(二)
2017-10-13 10:38:19 】 浏览:4635
Tags:比较 排序 IComparable IComparer 以及 它们 实现
new SortName()); foreach (Student item in studentList) { this.textBox1.Text += item.Name + "----" +item.Age.ToString() + "\r\n" ; } } } class Student:IComparable<Student> { public string Name { get; set; } public int Age { get; set; } #region IComparable<Student> Members public int CompareTo(Student other) { return Age.CompareTo(other.Age); } #endregion } class SortName: IComparer<Student> { #region IComparer<Student> Members public int Compare(Student x, Student y) { return x.Name.CompareTo(y.Name); } #endregion }

 

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇ArrayList排序Sort()方法(转) 下一篇DataGridView带图标的单元格实现

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目