![]() |
VOOZH | about |
Array.Sort Method is used to sort elements in a one-dimensional array. There are 17 methods in the overload list of this method. Here we will discuss the following methods:
This method sorts a pair of array objects based on the keys in the first array using the specified IComparer;T> generic interface. Here in the 2 arrays one contains the keys and the other contains the corresponding items.
Syntax: public static void Sort<TKey, TValue> (TKey[] keys, TValue[] items, IComparer comparer);
Here, TKey is the type of the elements of the key array and TValue the type of the elements of the items array.
Parameters:
keys: It is the one-dimensional array that contains the keys to sort.
items: It is the one-dimensional array that contains the items that correspond to the keys in keys.
comparer: It is the IComparer<T> generic interface implementation to use when comparing elements.
Exceptions:
Example:
The original order of elements in the array: H : A J : E K : D L : C I : F N : B M : G After Sorting: H : A I : F J : E K : D L : C M : G N : B
This method is used to sort a range of elements in a pair of array objects based on the keys in the first array. Here in the 2 arrays one contains the keys and the other contains the corresponding items.
Syntax: public static void Sort<TKey, TValue> (TKey[] keys, TValue[] items, IComparer comparer, int index, int len);
Here, TKey is the type of the elements of the key array and TValue is the type of the elements of the items array.
Parameters:
keys: It is the one-dimensional array that contains the keys to sort.
items: It is the one-dimensional array that contains the items that correspond to the keys in keys.
comparer: It is the IComparer<T> generic interface implementation to use when comparing elements.
index: It is the starting index of the range to sort.
len: It is the number of elements in the range to sort.
Exceptions:
Example:
The original order of elements in the array: H : A J : E K : D L : C I : F M : B N : G After Sorting: H : A I : F J : E K : D L : C M : B N : G
This method is used to sort a range of elements in a pair of array objects based on the keys in the first array using the specified IComparer<T> generic interface. Here in the 2 arrays one contains the keys and the other contains the corresponding items.
Syntax: public static void Sort<TKey,TValue> (TKey[] keys, TValue[] items, int index, int len, IComparer<TKey> comparer);
Parameters:
keys: It is the one-dimensional array that contains the keys to sort.
items: It is the one-dimensional array that contains the items that correspond to the keys in keys.
comparer: It is the IComparer<T> generic interface implementation to use when comparing elements.
index: It is the starting index of the range to sort.
len: It is the number of elements in the range to sort.
comparer: It is the IComparer<T> generic interface implementation to use when comparing elements.
Exceptions:
Example:
The original order of elements in the array: H : A J : E K : D L : C I : F M : B N : G After Sorting: H : A I : F J : E K : D L : C M : B N : G
Reference: