开发者

sorty List by ASC or DESC

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜