Sort a sub range Array objects (one for keys and other for values) based on the keys using specified IComparer in CSharp

Description

The following code shows how to sort a sub range Array objects (one for keys and other for values) based on the keys using specified IComparer.

Example


// www .  j  a  va  2 s .  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 };

        ReverseComparer rc = new ReverseComparer();
        Array.Sort(myValues, myValuesizes, 3, 3, rc);


        foreach(String s in myValues){
           Console.WriteLine(s);
        }

        foreach(int s in myValuesizes){
           Console.WriteLine(s);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var