Advertisement
Venciity

[C#] Array.sort example

Jan 9th, 2014
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. // sorce : http://www.dotnetperls.com/array-sort
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace TestSomeShits
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             Console.Write("Enter array length: ");
  16.             int length = int.Parse(Console.ReadLine());
  17.             int[] myArray = new int[length];
  18.  
  19.             //enter array elements
  20.             for (int i = 0; i < myArray.Length; i++)
  21.             {
  22.                 Console.Write("Number {0} = ", i + 1);
  23.                 myArray[i] = int.Parse(Console.ReadLine());
  24.             }
  25.  
  26.             Array.Sort(myArray);
  27.             Console.WriteLine();
  28.             Console.WriteLine("THE SORTED ARRAY IS :");
  29.             for (int i = 0; i < myArray.Length; i++)
  30.             {
  31.                 Console.WriteLine("Number {0}= {1}",i+1,myArray[i]);
  32.             }
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement