ArrayList sorting Sort () method), arraylistsort

Source: Internet
Author: User

ArrayList sorting Sort () method (convert), arraylistsort

// Use the Sort method to Sort the elements in the set. Sort has three methods for overloading. The declaration code is as follows. Public void Sort (); // Sort public void Sort (IComparer comparer) by comparing set elements; // Sort public void Sort (int index, int count, IComparer comparer) // Sort the specified range using a custom comparator. Note: to Sort all elements in the set using the Sort method, the IComparable interface must be implemented. Otherwise, will throw an exception. The first method is used to sort the instance using System; using System. collections; class Program {static void Main (string [] args) {ArrayList al = new ArrayList (); al. addRange (new string [8] {"Array1", "Array2", "Array3", "Array5", "Array4", "Array8", "Array7 ", "Array6"}); al. sort (); foreach (string s in al) {Console. writeLine (s);} Console. readLine ();}}

 

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.