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
精彩评论