::
::
::
::
::
- 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());
- }
posted on
2013-05-13 11:46
Object 罗
阅读(
165)
评论()
编辑
收藏
举报