Sorting list of string by lenght

Hi,
What’s wrong with my code? I couldn’t sort the liste by lenght of words.

static void Main(string[] args)

{

    var liste = new List<string>(0);

    int n = int.Parse(Console.ReadLine());

    for (int i = 0; i < n; i++)

    {

        string word = Console.ReadLine();

        liste.Add(word);

    }

    liste.OrderBy(x => x.Length).Reverse();

    foreach(var w in liste)

    {

        Console.WriteLine(w);

    }

}

Hey !
Think to specify the language you use in your message, the category is not so visible. :wink:
Reading the documentation is a reflex to have, a 2sec search gave me the answer to your question while I never use C#. Think about it next time.
About your question: OrderBy() return a new (sorted) list, so you have to store the result to use it. Or you can use Sort() which make the sorting “in place”. I.e in the same list.

OrderBy() is for sorting without mutating the original list, quite useful in functional programming style. You can also follow up with ThenBy(). Sort() mutates the list in place and is what you’re looking for here.