Sort sub range Arrays (one for keys and the other for values) based on keys using IComparable implementation of each key in CSharp
Description
The following code shows how to sort sub range Arrays (one for keys and the other for values) based on keys using IComparable implementation of each key.
Example
/* w w w.j a va 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 = {"40", "5", "3", "22", "1", "18" };
int[] myValuesizes = { 40, 5, 3, 22, 1, 18 };
Array.Sort(myValues, myValuesizes, 3, 3);
foreach(String s in myValues){
Console.WriteLine(s);
}
foreach(int s in myValuesizes){
Console.WriteLine(s);
}
}
}
The code above generates the following result.