sort all numbers up to 10 in csharp

To sort all the numbers up to 10 in C#, create an integer array of numbers from 1 to 10 and sort it using the built-in Array.Sort() function.

main.cs
int[] numbers = { 10, 1, 8, 3, 6, 5, 4, 7, 2, 9 }; // create an array of numbers from 1 to 10
Array.Sort(numbers); // sort the array in ascending order
152 chars
3 lines

Now, the numbers array will be sorted in ascending order from 1 to 10. You can print the sorted array to the console using the following code.

main.cs
foreach (int number in numbers)
{
    Console.Write(number + " ");
}
69 chars
5 lines

This will output: 1 2 3 4 5 6 7 8 9 10.

related categories

gistlibby LogSnag