Write a program to sort the given array in C#
Solution 1:
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { internal class Program { static void Main(string[] args) { // Input array int[] arr = { 1, 423, 6, 46, 34, 23, 13, 53, 4 }; int min =0, max =0; int length = arr.Length; List<int> list = arr.Cast<int>().ToList().OrderBy(x=> x).ToList(); arr = list.ToArray(); Array.ForEach(arr, Console.WriteLine); Console.ReadKey(); } } }
Output-
1 4 6 13 23 34 46 53 423
Comments
Post a Comment