Sort an Array Using LINQ
Sorting an array becomes a one-liner with LINQ's OrderBy.
int[] numbers = { 5, 2, 8, 1, 4 }; var sorted = numbers.OrderBy(n => n); Console.WriteLine(string.Join(", ", sorted));
Explanation: OrderBy arranges the numbers in ascending order, and string.Join is used to format the output for easy reading.