Sort a sub range Array using the IComparable implementation of each element of the Array in CSharp

Description

The following code shows how to sort a sub range Array using the IComparable implementation of each element of the Array.

Example


using System;/*  w  w  w .  j  a v a2  s  . c o  m*/
using System.Collections.Generic;

public class ReverseComparer: IComparer<string>
{
    public int Compare(string x, string y)
    {
        return y.CompareTo(x);
    }
}

public class Example
{
    public static void Main()
    {
        string[] myValues = {"2016", 
                              "1999", 
                              "2000", 
                              "1234",
                              "2001", 
                              "2345"};

        Array.Sort(myValues, 3, 3);

        foreach(String s in myValues){
           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