Sort sub range Array using the specified IComparer in CSharp
Description
The following code shows how to sort sub range Array using the specified IComparer.
Example
/* ww w . java 2s . c o m*/
using System;
using System.Collections.Generic;
public class ReverseComparer : IComparer<string>
{
public int Compare(string x, string y)
{
// Compare y and x in reverse order.
return y.CompareTo(x);
}
}
public class Example
{
public static void Main()
{
string[] myValues = {"2016",
"1999",
"2000",
"1234",
"2001",
"2345"};
Array.Sort(myValues, 3, 3, new ReverseComparer());
foreach (String s in myValues)
{
Console.WriteLine(s);
}
}
}
The code above generates the following result.