How to sort array of strings in descending order using Linq with C#

1 Answer

0 votes
using System;
using System.Linq;

class Program
{
    static void Main() {
        string[] arr = { "c#", "c", "c++", "python", "java" };

        var result = from n in arr
                        orderby n descending
                        select n;

        foreach (string s in result)
                Console.WriteLine(s);
    }
}




/*
run:

python
java
c++
c#
c

*/

 



answered Jan 2, 2023 by avibootz

Related questions

...