C# Array Sort(T[], Int32, Int32)

Description

Array Sort(T[], Int32, Int32)sorts the elements in a range of elements in an Array using the IComparable generic interface implementation of each element of the Array.

Syntax

Array.Sort<T>(T[], Int32, Int32) has the following syntax.


public static void Sort<T>(
  T[] array,//from   w  ww . j a v a 2s  .c  o m
  int index,
  int length
)

Parameters

Array.Sort<T>(T[], Int32, Int32) has the following parameters.

  • T - The type of the elements of the array.
  • array - The one-dimensional, zero-based Array to sort
  • index - The starting index of the range to sort.
  • length - The number of elements in the range to sort.

Returns

Array.Sort(T[], Int32, Int32) method returns

Example


using System;/*from   w  w  w .j  a  v a 2 s. c om*/
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);
    }
}




















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version