问题

我有一个列表:

 dave
maggie
john
stuart
john
john
dave
john
maggie
maggie
 

我想要的结果是:

 john
john
john
john
maggie
maggie
maggie
dave
dave
stuart
 

  最佳答案

首先我对它们进行分组.然后按每个组的计数排序.最后使用SelectMany从组中的每个名称获得一个平坦的结构.

 var myList = new List<string>()
{
    "dave",
    "maggie",
    "john",
    "stuart",
    "john",
    "dave",
    "john",
};

var result = myList
    .GroupBy(x => x)
    .OrderByDescending(x => x.Count())
    .SelectMany(x => x)
    .ToList();
 

  相同标签的其他问题

c#arrayslistlinqsorting