The sort method of the. NET Array class classifies values

Source: Internet
Author: User
Tags array contains integer interface key net sort tostring

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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.