// C# program to demonstrate the use of
// Array.Sort<TKey, TValue>(TKey[], TValue[],
// Int32, Int32, IComparer<TKey>) Method
using System;
using System.Collections.Generic;
class compare : IComparer<string> {
public int Compare(string x, string y)
{
// Compare x to y
return x.CompareTo(y);
}
}
// Driver Class
class GFG {
// Main Method
public static void Main()
{
// Initialize two array
String[] arr1 = {"H", "J", "K",
"L", "I", "M", "N"};
String[] arr2 = {"A", "E", "D",
"C", "F", "B", "G"};
// Instantiate the IComparer object
compare g = new compare();
// Display original values of the array
Console.WriteLine("The original order of"
+ " elements in the array:");
Display(arr1, arr2);
// Sort the array
// "arr1" is keys array
// "arr2" is items array
// "g" is IComparer<TKey> object
// start index 1
// range upto index 5
Array.Sort(arr1, arr2, 1, 5, g);
Console.WriteLine("\nAfter Sorting: ");
Display(arr1, arr2);
}
// Display function
public static void Display(String[] arr1, String[] arr2)
{
for (int i = 0; i < arr1.Length; i++)
{
Console.WriteLine(arr1[i] + " : " + arr2[i]);
}
}
}