惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - ghx88

工具记录 [ 转]discuz 的加密与解密函数authcode解析 Balsamiq Mockups完全手册[转] 使用安全json parser防止json注入 [转]Yahoo!网站性能最佳体验的34条黄金守则——内容 人生的时间管理法则 JavaScript 读取地址栏参数 无题 唐僧的家书 如何成为一个专家 [原创]JQuery实现表格的列列交换 - ghx88 - 博客园 asp.net2 统一搜索引擎关键字编码[转] 中国的数学教育方式 别浪费了你的大内存[转] QQ空间免费养5级花和拥有人参果 把网速提高4倍的方法和动画教程 关于charset在blueidea的帖子[转] 林蛋大 多吃葡萄可以排毒[转]
使类支持排序
ghx88 · 2007-09-02 · via 博客园 - ghx88

  1using System;
  2using System.Collections.Generic;
  3using System.Text;
  4using System.Collections;
  5
  6namespace ConsoleApplication1
  7{
  8    /// <summary>
  9    /// 继承IComparable接口,使类可以支持排序,排序的算法在Array类中
 10    /// </summary>

 11    public class Student : IComparable 
 12    {
 13        private string m_Name;
 14        private int m_Score;
 15
 16        public Student() { }
 17
 18        public Student(string name, int score) 
 19        {
 20            this.m_Name = name;
 21            this.m_Score = score;
 22        }

 23
 24        public string Name
 25        {
 26            get return m_Name; }
 27            set { m_Name = value; }
 28        }

 29
 30        public int Score
 31        {
 32            get return m_Score; }
 33            set { m_Score = value; }
 34        }

 35
 36        IComparable 成员
 65      
 66    }

 67
 68    public class StudentSortByName :  IComparer 
 69    {
 70
 71        IComparer 成员
 91    }

 92
 93    class Program
 94    {
 95        static void Main(string[] args)
 96        {
 97            Student[] students = new Student[10];
 98            Random rd = new Random();
 99            for (int i = 0; i < 10; i++
100            {
101                students[i] = new Student("Student" + i.ToString(), rd.Next(100));
102            }

103            Console.WriteLine("分数从小到大排序");
104            Array.Sort(students);
105            ShowStudents(students);
106
107            Console.WriteLine("分数从大到小排序");
108            Array.Reverse(students);
109            ShowStudents(students);
110
111            Console.WriteLine("以学生名称排序");
112            Array.Sort(students, new StudentSortByName());
113            ShowStudents(students);
114            Console.ReadLine();
115
116
117        }

118
119        private static void ShowStudents(Student[] students)
120        {
121            foreach (Student s in students)
122            {
123                Console.WriteLine("Name :" + s.Name + " Score :" + s.Score.ToString());
124            }

125        }

126    }

127}

128