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
notList
并且您在没有明显原因的情况下调用了ToList
两次。您的代码无法编译。您的结果是List
notList
并且您在没有明显原因的情况下调用了ToList
两次。您的代码无法编译。您的结果是List
notList
并且您在没有明显原因的情况下调用了ToList
两次。您的代码无法编译。您的结果是List
notList
而且您在没有明显原因的情况下调用了ToList
两次。