System Namespace Array Class
Sorts a section of a pair of one-dimensional Array objects ( one contains the keys and the other contains the corresponding items ) based on the keys in the first Array using the IComparable interface implemented by each key.
[ VB ]
<Serializable>
Overloads Public
Shared Sub Sort ( _
ByVal keys As Array, _
ByVal items As Array, _
ByVal index As Integer, _
ByVal length As Integer _
)
[ C# ]
[Serializable]
public static void Sort (
Array keys,
Array items,
int index,
int length
);
[ C++ ]
[Serializable]
public: static void Sort (
Array* keys,
Array* items,
int index,
int length
);
[JScript ]
public Serializable
static function Sort (
keys : Array,
items : Array,
index : int,
length : int
);
- keys
- The one-dimensional Array that contains the keys to sort.
- items
- The one-dimensional Array that contains the items that correspond to each of the keys in the keys Array.
-or-
A null reference ( Nothing in Visual Basic ) to sort only the keys Array.
- index
- The starting index of the range to sort.
- length
- The number of elements in the range to sort.
Exception Type |
Condition |
ArgumentNullException |
keys is a null reference ( Nothing in Visual Basic ). |
RankException |
The keys Array is multidimensional.
-or-
items is not a null reference ( Nothing in Visual Basic ) and is multidimensional.
|
ArgumentOutOfRangeException |
index is less than the lower bound of keys.
-or-
length is less than zero.
|
ArgumentException |
items is not a null reference ( Nothing in Visual Basic ) , and the lower bound of keys does not match the lower bound of items.
-or-
index and length do not specify a valid range in the keys Array.
-or-
items is not a null reference ( Nothing ) , and index and length do not specify a valid range in the items Array.
|
InvalidOperationException |
The comparer throws an exception. |
Each key in the keys Array has a corresponding item in the items Array. When a key is repositioned during the sorting, the corresponding item in the items Array is similarly repositioned. Therefore, the items Array is sorted according to the arrangement of the corresponding keys in the keys Array.
Each key within the specified section of the keys Array must implement the IComparable interface to be capable of comparisons with every other key.
If the sort is not successfully completed, the results are undefined.
This method uses the QuickSort algorithm. This is an O ( n log2n ) operation, where n is the number of elements to sort.
Array Members Array.Sort Overload List IComparable BinarySearch