Sort method
The static sort method using the array class is the easiest way to categorize the contents of an array. List A describes how to apply this method by categorizing a set of names.
It generates the following results, which show the list of names before and after the calling classification method:
The following are the referenced contents: 0. Howard, Ryan 1. Allen, Ray. 2. Pujols, Albert 3. Iverson, Allen 0. Allen, Ray. 1. Howard, Ryan 2. Iverson, Allen 3. Pujols, Albert |
Here is the corresponding vb.net code:
The following are the referenced contents: Dim x as Integer Dim names (3) as String Names (0) = "Howard, Ryan" Names (1) = "Allen, Ray" Names (2) = "Pujols, Albert" Names (3) = "Iverson, Allen" For x = 0 to (names. LENGTH-1) Console.WriteLine (CSTR (x) + "." + names (x). ToString ()) Next x Array.Sort (names) For x = 0 to (names. LENGTH-1) Console.WriteLine (CSTR (x) + "." + names (x). ToString ()) Next x |
The sort method of the array class can classify the array contents in various forms. Now that you understand the simplest form of application of this method, here are some other uses:
Sort (array, array); The one-to-one dimension array (one containing the key and the other containing the corresponding item) is categorized according to the keys in the first array.
Sort (Array, IComparable): classifies elements in a one-dimensional array with the specified IComparable interface.
Sort (array, array, IComparable): A one-to-one dimension array (one containing the key and the other containing the corresponding item) is categorized with the specified IComparable interface based on the keys in the first array.
Sort (array, Integer, integer): A one-dimensional array that specifies an element in a part of the beginning and end position (an integer value) to classify.
Sort (array, array, Integer, integer): A one-to-one dimension array (one containing the key and the other containing the corresponding item) is categorized according to the keys in the first array.
Sort (Array, Integer, Integer, IComparable): Sorts the elements in a one-dimensional array with the specified IComparable interface.
Sort (array, array, Integer, Integer, IComparable): The specified IComparable interface classifies a one-to-one dimension array (one containing the key and the other containing the corresponding item) from the key in the first array.
You can use the default behavior of the array class to classify an entire array and a portion of an array; You can also specify a detailed classification method through a special IComparable interface. The example in list B uses two arrays, one array contains keys and the other contains the corresponding items to categorize. It is the same as the first example of adding an array of keys.