Sorts and array in ascending order, then reverses the elements : Array Sort : Collections Data Structure C# Source Code


Custom Search

C# Source Code » 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 + " ");
             }
        }
    }


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Collections Data Structure
» Array Sort