How to sort array in ascending order using Linq in C#

1 Answer

0 votes
using System;
using System.Linq;

class Program
{
    static void Main() {
        int[] arr = { 4, 6, 1, 9, 3 };

        var sort_arr = from n in arr
                        orderby n
                        select n;

        foreach (int number in sort_arr)
            Console.WriteLine(number);
    }
}
 
 
 
 
/*
run:
 
1
3
4
6
9
 
*/

 



answered Mar 11, 2021 by avibootz

Related questions

1 answer 119 views
1 answer 210 views
1 answer 134 views
2 answers 197 views
1 answer 136 views
1 answer 233 views
1 answer 174 views
...