Method in array in C # (example)

Source: Internet
Author: User

In the array object in C #, you can use the reverse () method to reverse the element order in the array. The reverse () method is a static method, so as a parameter, the array elements that need to be reversed are passed to the reverse () method.

Array. Reverse (interger );

The sort () method can be used to sort the elements of an array.

Array. Sort (integer );

Consider an example where the student scores are stored in the array and data needs to be sorted to determine the highest score and the lowest score.

Using System;
Using System. Collections. Generic;
Using System. text;

Namespace Leleapplication2
{
Class Program
{
Static   Void Main ( String [] ARGs)
{
Int [] Marks =   {70,75,84,53,46,90,25} ;
Int I = Marks. length;

Console. Write ("Initial sorting: 70, 75, 84, 53, 46, 90, 25");
System. Threading. thread. Sleep (2000);

Array. Sort (marks );
Console. writeline ("");
Console. writeline ("Sorted in ascending order:");
System. Threading. thread. Sleep (2000);

For ( Int X =   0 ; X < I; x ++ )
{
Console. writeline (Marks [x]);
System. Threading. thread. Sleep (1000);
}
Console. Read ();
}
}
}

 

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.