实现IComparable的CompareTo接口
SortedSet<T>: 表示按排序顺序保持的对象的集合。
T:必须要实现IComparable接口的CompareTo方法
public static SortedSet<Survey> GetSortedSet() { SortedSet<Survey> ss = new SortedSet<Survey>(); ss.Add(new Survey{SurveyID=2,ProvinceId="A1"}); ss.Add(new Survey{SurveyID=1,ProvinceId="A2"}); ss.Add(new Survey{SurveyID=5,ProvinceId="A3"}); return ss; }
public class Survey:IComparable { public int SurveyID { get; set; } public string ProvinceId { get; set; } public int CompareTo(object obj) { if (obj == null) return 1; Survey survey = obj as Survey; if (survey!=null) { return this.SurveyID.CompareTo(survey.SurveyID); } else { throw new ArgumentException("Object is not a Survey"); } } }

浙公网安备 33010602011771号