Csharp/C Sharp/Collections Data Structure/Array Sort
Sorts and array in ascending order, then reverses the elements
// Sort.cs -- Sorts and array in ascending order, then reverses the elements
using System;
public class Sort
{
static public void Main ()
{
DateTime now = DateTime.Now;
Random rand = new Random ((int) now.Millisecond);
int [] Arr = new int [12];
for (int x = 0; x < Arr.Length; ++x)
{
Arr [x] = rand.Next () % 101;
}
Console.WriteLine ("The unsorted array elements:");
foreach (int x in Arr)
{
Console.Write (x + " ");
}
Array.Sort (Arr);
Console.WriteLine ("\r\n\r\nThe array sorted in ascending order:");
foreach (int x in Arr)
{
Console.Write (x + " ");
}
Array.Reverse (Arr);
Console.WriteLine ("\r\n\r\nThe array sorted in descending order:");
foreach (int x in Arr)
{
Console.Write (x + " ");
}
}
}
System.Array: Sorting and Searching
using System;
public class SortingandSearchingArray
{
public static void Main()
{
int[] arr = {5, 1, 10, 33, 100, 4};
Array.Sort(arr);
foreach (int v in arr)
Console.WriteLine("Element: {0}", v);
}
}