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.