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

Description

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

Example


//w ww .ja v a2s. com
using System;
using System.Collections;

class myReverserClass : IComparer  {

      // Calls CaseInsensitiveComparer.Compare with the parameters reversed. 
      int IComparer.Compare( Object x, Object y )  {
          return( (new CaseInsensitiveComparer()).Compare( y, x ) );
      }

}
   
public class SamplesArray  {
   public static void Main()  {

      String[] myArr = { "The", "QUICK", "BROWN", "FOX", "jumps", "over", "the", "lazy", "dog" };
      IComparer myComparer = new myReverserClass();

      Array.Sort( myArr, 1, 3 );
      
      foreach(String s in myArr){
         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