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.          }  
  • 相关阅读:
    P1073 最优贸易
    window.btoa()方法;使字符编码成base64的形式
    centOs7 忘记root密码
    window.addEventListener()/window.postMessage(”text“, '*')
    $(function(){})理解
    跨域资源共享/option 请求产生原因
    Angular: Can't bind to 'ngModel' since it isn't a known property of 'input'问题解决
    TypeScript
    盒子模型
    理解事件捕获等
  • 原文地址:https://www.cnblogs.com/lx0551/p/3075372.html
Copyright © 2011-2022 走看看