-
C#List 排序
- public class Book
- {
- private string name;
- public string Name
- {
- get { return name; }
- set { name = value; }
- }
- private int year;
- public int Year
- {
- get { return year; }
- set { year = value; }
- }
- private int price;
- public int Price
- {
- get { return price; }
- set { price = value; }
- }
- public Book(string name,int year, int price)
- {
- Name = name;
- Year = year;
- Price = price;
- }
- }
-
- public class ComparableBookPriceInc : IComparer<Book>
- {
- public int Compare(Book b1, Book b2)
- {
- return b1.Price.CompareTo(b2.Price);
- }
- }
-
- public class ComparableBookYearInc : IComparer<Book>
- {
- public int Compare(Book b1, Book b2)
- {
- return b1.Year.CompareTo(b2.Year);
- }
- }
-
- static void Main(string[] args)
- {
- List<Book> listBook = new List<Book>();
- listBook.Sort(new ComparableBookPriceInc());
- listBook.Sort(new ComparableBookYearInc());
- }
-
相关阅读:
[转]我们应该做什么样的研究
[转]面向服务架构(SOA)和企业服务总线(ESB)
[转]程序员应知——团队精神
vs2010 调试快捷键
asp.net 获取ip的6种方法
解决了防止用户重复登陆和session超时
IE 10 也能随网站应变,图标决定一切!
Sony VAIO Duo 11 游戏性能测试
翻出Windows 8 当中的游戏管理器
Office 2013预览版已到期,需要付费才可正常使用
-
原文地址:https://www.cnblogs.com/lx0551/p/3075372.html
Copyright © 2020-2023
润新知