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
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 sortindex
- 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);
}
}