Is it possible to sorty List by ASC or DESC?
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
}
Two pretty straightforward choices: implement a ReverseAdvertisementsComparer
class:
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);
}
}
Or just call List<Advertisements>.Sort()
followed by List<Advertisements>.Reverse()
.
return y.Country.Name.CompareTo(x.Country.Name);
To reverse it
精彩评论