LINQ: Order By Count of most common value

后端 未结 1 1021
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-18 05:09

I\'m trying to create an \"ordered\" List of objects in c#, where the list will be ordered by the most common occurrences of values in ImdbId property. I am not using databa

1条回答
  •  生来不讨喜
    2021-01-18 05:37

    Try this:

    var newList = List.GroupBy(x=>x.ImdbId)
                      .OrderByDescending(g=>g.Count())
                      .SelectMany(g=>g).ToList();
    

    0 讨论(0)
提交回复
热议问题