实体类实现IComparable接口,而且必须实现CompareTo方法
实体类定义如下:
1 class Info:IComparable 2 { 3 public int Id { get; set; } 4 public string Name { get; set; } 5 6 public int CompareTo(object obj) { 7 int result; 8 try 9 { 10 Info info = obj as Info; 11 if (this.Id > info.Id) 12 { 13 result = 0; 14 } 15 else 16 result = 1; 17 return result; 18 } 19 catch (Exception ex) { throw new Exception(ex.Message); } 20 } 21 }