Sort a range of Array using the specified IComparer in CSharp
Description
The following code shows how to sort a range of Array using the specified IComparer.
Example
// ww w . j av a 2 s.c om
using System;
using System.Collections;
class myReverserClass : IComparer {
// Calls CaseInsensitiveComparer.Compare with the parameters reversed.
int IComparer.Compare( Object x, Object y ) {
return( (new CaseInsensitiveComparer()).Compare( y, x ) );
}
}
public class SamplesArray {
public static void Main() {
String[] myArr = { "A", "B", "C", "F", "E", "o", "t", "P", "D" };
IComparer myComparer = new myReverserClass();
Array.Sort( myArr, 1, 3, myComparer );
foreach(String s in myArr){
Console.WriteLine(s);
}
}
}
The code above generates the following result.