/// <summary> /// 比较当前对象和同一类型的另一对象。用于排序。 /// </summary> /// <param name="other">与此对象进行比较的对象。</param> /// <returns>一个 32 位有符号整数,指示要比较的对象的相对顺序。</returns> public int CompareTo(ProductFamily other) { int s = this.Sort.CompareTo(other.Sort); if (s == 0) { return(this.Code.CompareTo(other.Code)); } else { return(s); } }
/// <summary> /// 比较当前对象和同一类型的另一对象。用于排序。 /// </summary> /// <param name="obj">与此对象进行比较的对象。</param> /// <returns>一个 32 位有符号整数,指示要比较的对象的相对顺序。</returns> /// <remarks>也可以添加一个范型实现。</remarks> public override int CompareTo(object obj) { if (obj is ProductFamily) { ProductFamily temp = (ProductFamily)obj; int s = this.Sort.CompareTo(temp.Sort); if (s == 0) { return(this.Code.CompareTo(temp.Code)); } else { return(s); } } throw new ArgumentException("object is not a WarranyEntry"); }