C # sorting of arrays (forward and backward)

Source: Internet
Author: User

C # sorting of arrays (forward and backward)

This sort is super simple!

Using system; using system. collections. generic; using system. LINQ; using system. text; namespace consoleapplication4 {class program {static void main (string [] ARGs) {string [] STR = {"D", "H", "A", "C ", "G", "T", "E", "U", "B"}; var lowtohigh = from P in STR orderby P select P; // LINQ STR = lowtohigh. toarray (); foreach (VAR item in Str) {console. writeline ("Forward order" + item ); // forward order} // ============================================== ==================== for (INT I = 0; I <Str. length/2; I ++) {string temp = STR [I]; // create a variable to exchange STR [I] = STR [Str. length-i-1]; STR [Str. length-I-1] = temp; // intercommunication} foreach (VAR newstr in Str) {console. writeline ("reverse order:" + newstr);} console. writeline ("====================================== "); //###################################### ######### int [] num = {5, 78, 9, 1, 8, 4, 2, 88, 3}; var lowtohigh1 = from P in num orderby P select P; num = lowtohigh1.toarray (); foreach (VAR num1 in num) {console. writeline (num1); // forward order} For (INT I = 0; I <num. length/2; I ++) {int temp = num [I]; // create a variable to exchange num [I] = num [num. length-I-1]; num [num. length-I-1] = temp; // intercommunication} foreach (VAR newnum in num) {console. writeline ("reverse order:" + newnum);} console. writeline ("====================================== ") ;}}}

  

Result:

 

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.