zoukankan      html  css  js  c++  java
  • C#List 排序

    1. public class Book  
    2.     {  
    3.         private string name;  
    4.         public string Name  
    5.         {  
    6.             get { return name; }  
    7.             set { name = value; }  
    8.         }  
    9.         private int year;  
    10.         public int Year  
    11.         {  
    12.             get { return year; }  
    13.             set { year = value; }  
    14.         }  
    15.         private int price;  
    16.         public int Price  
    17.         {  
    18.             get { return price; }  
    19.             set { price = value; }  
    20.         }  
    21.         public Book(string name,int year, int price)  
    22.         {  
    23.             Name = name;  
    24.             Year = year;  
    25.             Price = price;  
    26.         }  
    27.     }  
    28.    
    29. public class ComparableBookPriceInc : IComparer<Book>  
    30.     {  
    31.         public int Compare(Book b1, Book b2)  
    32.         {  
    33.             return b1.Price.CompareTo(b2.Price);  
    34.         }  
    35.     }  
    36.    
    37.  public class ComparableBookYearInc : IComparer<Book>  
    38.     {  
    39.         public int Compare(Book b1, Book b2)  
    40.         {  
    41.             return b1.Year.CompareTo(b2.Year);  
    42.         }  
    43.     }  
    44.    
    45.  static void Main(string[] args)  
    46.         {  
    47.             List<Book> listBook = new List<Book>();  
    48.             listBook.Sort(new ComparableBookPriceInc());  
    49.             listBook.Sort(new ComparableBookYearInc());  
    50.          }  
  • 相关阅读:
    HTTP协议详解(真的很经典)
    几点建议,让Redis在你的系统中发挥更大作用
    Redis能干啥?细看11种Web应用场景
    Java中使用Jedis操作Redis
    java的锁机制——synchronized
    web开发中的两把锁之数据库锁:(高并发--乐观锁、悲观锁)
    一分钟教你知道乐观锁和悲观锁的区别
    $^,$@,$?,$<,$(@D),$(@F) of makefile
    linux shared lib 使用与编译
    makefile learning
  • 原文地址:https://www.cnblogs.com/lx0551/p/3075372.html
Copyright © 2011-2022 走看看