A summary of the sort functions in C # _c# tutorial

Source: Internet
Author: User

The sort function ranks the data in an array in ascending order (where the sort function has many overloads, no more than one by one of the description)

The reverse function is sorted in descending order from the data in the array.

static void Main (string[] args)
 { 
//Sort, Reverse Sort application Example
int[] intarr = {1,4,2,3,99,34,22,16,8,100};
Console.WriteLine ("Original array is:");
for (int i = 0; i < intarr.length i++)
{
 Console.Write (Intarr.getvalue (i));
 Console.Write ("");
}
Console.WriteLine ();
Array.Sort (intarr); The function to sort in ascending order;
Console.WriteLine ("Sorted in ascending order:");
for (int i = 0; i < intarr.length i++)
{
 Console.Write (Intarr.getvalue (i));
 Console.Write ("");
}
Console.WriteLine ();
Array.reverse (intarr); The function to sort in descending order;
Console.WriteLine ("Sorted by descending order is:");
for (int i = 0; i < intarr.length i++)
{
 Console.Write (Intarr.getvalue (i));
 Console.Write ("");
}


How do I connect two arrays to sort operations? For example, in the student's information has the number and the name, according to the student number output students how to achieve???

static void Main (string [] args)
 {
  int [] arrstunum=new []{1,5,4,2,3};
  string [] arrstuname=new []{"small", "Xiao Zhao", "Wei", "Danny", "Less than"};
  Console.WriteLine ("The Student information before the order is:");
  for (int i=0;i<arrstunum.length;i++)
  {
 Console.WriteLine ("{0} ({1})", Arrstuname[i],arrstunum[i]);
  }

  Console.WriteLine ("The Student information after the order is:");
  Array.Sort (Arrstunum,arrstuname); Note: Reverse has no such usage; for
  (int i = 0; i < arrstunum.length; i++)
  {
 Console.WriteLine (' {0} ({1}) ', Arrs Tuname[i], arrstunum[i]);
Console.read ();
 }

The above summary of the sort function in C # is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.

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.