是否可以按ASC或DESC对List进行排序?
private class CompAdvertisements : IComparer<Advertisements>
{
#region IComparer<Advertisements> Members
public int Compare(Advertisements x, Advertisements y)
{
return x.Country.Name.CompareTo(y.Country.Name);
}
#endregion
}
答案 0 :(得分:2)
两个非常简单的选择:实现ReverseAdvertisementsComparer
类:
private class ReverseAdvertisementsComparer: IComparer<Advertisements>
{
public int Compare(Advertisements x, Advertisements y)
{
// notice: reversed x and y
return y.Country.Name.CompareTo(x.Country.Name);
}
}
或者只需拨打List<Advertisements>.Sort()
,然后拨打List<Advertisements>.Reverse()
。
答案 1 :(得分:0)
return y.Country.Name.CompareTo(x.Country.Name);
要扭转它