Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无字典有序分组_C#_Linq - Fatal编程技术网

C# 无字典有序分组

C# 无字典有序分组,c#,linq,C#,Linq,我根据他们所服务的煤矿对火车旅行进行分组,然后从人口最多的煤矿开始处理每一组 List<List<Trip>> tripsByMine = trips.GroupBy(x => x.demand.Mine) .ToDictionary(x => x.Key, x => x.ToList()) .Values.Or

我根据他们所服务的煤矿对火车旅行进行分组,然后从人口最多的煤矿开始处理每一组

List<List<Trip>> tripsByMine = trips.GroupBy(x => x.demand.Mine)
                                    .ToDictionary(x => x.Key, x => x.ToList())
                                    .Values.OrderByDescending(x => x.Count)
                                    .ToList();
List tripsByMine=trips.GroupBy(x=>x.demand.Mine)
.ToDictionary(x=>x.Key,x=>x.ToList())
.Values.OrderByDescending(x=>x.Count)
.ToList();
在我看来,
ToDictionary
调用是多余的,因为我只需要
值。是否有较短的方法获得相同的结果?

可能的解决方案:

    List<List<Trip>> tripsByMine = trips.GroupBy(x => x.demand.Mine)
                                        .Select(x => new {Key=x.Key, Values=x,Count=x.Count()})
                                        .OrderByDescending(x => x.Count)
.Select(x=>x.Values.ToList())
                                        .ToList();
List tripsByMine=trips.GroupBy(x=>x.demand.Mine)
.Select(x=>new{Key=x.Key,Values=x,Count=x.Count()})
.OrderByDescending(x=>x.Count)
.Select(x=>x.Values.ToList())
.ToList();
可能的解决方案:

    List<List<Trip>> tripsByMine = trips.GroupBy(x => x.demand.Mine)
                                        .Select(x => new {Key=x.Key, Values=x,Count=x.Count()})
                                        .OrderByDescending(x => x.Count)
.Select(x=>x.Values.ToList())
                                        .ToList();
List tripsByMine=trips.GroupBy(x=>x.demand.Mine)
.Select(x=>new{Key=x.Key,Values=x,Count=x.Count()})
.OrderByDescending(x=>x.Count)
.Select(x=>x.Values.ToList())
.ToList();
可能的解决方案:

    List<List<Trip>> tripsByMine = trips.GroupBy(x => x.demand.Mine)
                                        .Select(x => new {Key=x.Key, Values=x,Count=x.Count()})
                                        .OrderByDescending(x => x.Count)
.Select(x=>x.Values.ToList())
                                        .ToList();
List tripsByMine=trips.GroupBy(x=>x.demand.Mine)
.Select(x=>new{Key=x.Key,Values=x,Count=x.Count()})
.OrderByDescending(x=>x.Count)
.Select(x=>x.Values.ToList())
.ToList();
可能的解决方案:

    List<List<Trip>> tripsByMine = trips.GroupBy(x => x.demand.Mine)
                                        .Select(x => new {Key=x.Key, Values=x,Count=x.Count()})
                                        .OrderByDescending(x => x.Count)
.Select(x=>x.Values.ToList())
                                        .ToList();
List tripsByMine=trips.GroupBy(x=>x.demand.Mine)
.Select(x=>new{Key=x.Key,Values=x,Count=x.Count()})
.OrderByDescending(x=>x.Count)
.Select(x=>x.Values.ToList())
.ToList();
试试这个

List<List<Trip>> tripsByMine2 = trips.GroupBy(x => x.demand.Mine)
    .Select(x => x.ToList())
     .OrderByDescending(x => x.Count)
     .ToList();
List tripsByMine2=trips.GroupBy(x=>x.demand.Mine)
.Select(x=>x.ToList())
.OrderByDescending(x=>x.Count)
.ToList();
试试这个

List<List<Trip>> tripsByMine2 = trips.GroupBy(x => x.demand.Mine)
    .Select(x => x.ToList())
     .OrderByDescending(x => x.Count)
     .ToList();
List tripsByMine2=trips.GroupBy(x=>x.demand.Mine)
.Select(x=>x.ToList())
.OrderByDescending(x=>x.Count)
.ToList();
试试这个

List<List<Trip>> tripsByMine2 = trips.GroupBy(x => x.demand.Mine)
    .Select(x => x.ToList())
     .OrderByDescending(x => x.Count)
     .ToList();
List tripsByMine2=trips.GroupBy(x=>x.demand.Mine)
.Select(x=>x.ToList())
.OrderByDescending(x=>x.Count)
.ToList();
试试这个

List<List<Trip>> tripsByMine2 = trips.GroupBy(x => x.demand.Mine)
    .Select(x => x.ToList())
     .OrderByDescending(x => x.Count)
     .ToList();
List tripsByMine2=trips.GroupBy(x=>x.demand.Mine)
.Select(x=>x.ToList())
.OrderByDescending(x=>x.Count)
.ToList();

您的代码无法编译。您的结果是
List
not
List
并且您在没有明显原因的情况下调用了
ToList
两次。您的代码无法编译。您的结果是
List
not
List
并且您在没有明显原因的情况下调用了
ToList
两次。您的代码无法编译。您的结果是
List
not
List
并且您在没有明显原因的情况下调用了
ToList
两次。您的代码无法编译。您的结果是
List
not
List
而且您在没有明显原因的情况下调用了
ToList
两次。