OrderBy descending in Lambda expression?

后端 未结 6 1515
梦谈多话
梦谈多话 2020-12-02 05:12

I know in normal Linq grammar, orderby xxx descending is very easy, but how do I do this in Lambda expression?

6条回答
  •  遥遥无期
    2020-12-02 06:06

    Try this:

    List list = new List();
    list.Add(1);
    list.Add(5);
    list.Add(4);
    list.Add(3);
    list.Add(2);
    
    foreach (var item in list.OrderByDescending(x => x))
    {
        Console.WriteLine(item);                
    }
    

提交回复
热议问题