ArraySortTKey, TValue Method (TKey, TValue, Int32, Int32, IComparerTKey) |
Sorts a range of elements in a pair of
Array objects (one contains the keys and the other contains the corresponding items) based on the keys in the first
Array using the specified
IComparerT generic interface.
Namespace: SystemAssembly: mscorlib (in mscorlib.dll) Version: 4.0.0.0
Syntax public static void Sort<TKey, TValue>(
TKey[] keys,
TValue[] items,
int index,
int length,
IComparer<TKey> comparer
)
Parameters
- keys
- Type: TKey
The one-dimensional, zero-based Array that contains the keys to sort. - items
- Type: TValue
The one-dimensional, zero-based Array that contains the items that correspond to the keys in keys, or null to sort only keys. - index
- Type: SystemInt32
The starting index of the range to sort. - length
- Type: SystemInt32
The number of elements in the range to sort. - comparer
- Type: System.Collections.GenericIComparerTKey
The IComparerT generic interface implementation to use when comparing elements, or null to use the IComparableT generic interface implementation of each element.
Type Parameters
- TKey
- The type of the elements of the key array.
- TValue
- The type of the elements of the items array.
Exceptions Exception | Condition |
---|
ArgumentNullException | keys is null. |
ArgumentOutOfRangeException | index is less than the lower bound of keys.-or-length is less than zero. |
ArgumentException | items is not null, and the lower bound of keys does not match the lower bound of items.-or-items is not null, and the length of keys is greater than the length of items.-or-index and length do not specify a valid range in the keysArray.-or-items is not null, and index and length do not specify a valid range in the itemsArray. -or-The implementation of comparer caused an error during the sort. For example, comparer might not return 0 when comparing an item with itself. |
InvalidOperationException | comparer is null, and one or more elements in the keysArray do not implement the IComparableT generic interface. |
See Also