开发者

Please explain me following code. interfaces, class

I am not able to understand following piedce of code. Specifically, this line of code

al.Sort(new reverseSort());

Code:

public class reverseSort : IComparer
{
    int IComparer.Compare(Object x, Object y)
    {
        return ((new CaseInsensitiveComparer()).Compare(y, x));
    }
}

ArrayList al = new开发者_StackOverflow社区 ArrayList();
        al.AddRange(new string[] { "Hello", "world", "this", "is", "a", "test" });

        al.Sort(new reverseSort());

        foreach (object s in al)
            Console.WriteLine(s.ToString());

Output:

world this test is Hello A


al.Sort(new reverseSort());

Calls Sort on your array al, using a custom defined comparer reverseSort, which is defined with the opposite sense of ordering to the default comparer

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜