Csharp/C Sharp/Collections Data Structure/Array Sort — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 18:31, 26 мая 2010
Sorts and array in ascending order, then reverses the elements
<source lang="csharp"> // 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 + " "); } } }
</source>
System.Array: Sorting and Searching
<source lang="csharp"> 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); }
}
</source>