|
Friday, 23 December 2011 00:21 |
To sort array of primitive types such as int, double or string use method Array.Sort(Array) with the array as a paramater. The primitive types implements interface IComparable, which is internally used by the Sort method (it calls IComparable.ComĀpareTo method). See example how to sort int array:
// sort int array
int[] intArray = new int[5] { 8, 10, 2, 6, 3 };
Array.Sort(intArray);
// write array
foreach (int i in intArray) Console.Write(i + " ");
//OUTPUT
2 3 6 8 10
 Read more: |