public class RebarUnique{ public Rebar MRebar { get; set; } public Point2d Point2d { get; set; }}public class Rebar{ public string Number { get; set; } public int Type { get; set; } public int Fi { get; set; }}我有清单:List<RebarUnique> rebarUnique;[{{Number: 1, Type: 1, Fi: 12}, (0,0)},{{Number: 1, Type: 1, Fi: 12}, (0,10)},{{Number: 2, Type: 1, Fi: 12}, (15,18)},{{Number: 3, Type: 1, Fi: 12}, (25,34)},{{Number: 1, Type: 1, Fi: 12}, (25,34)},{{Number: 3, Type: 1, Fi: 12}, (13,38)}]我想得到一个清单:通过...分组 Number按Point2d( Y coordinate)排序返回Number具有最低值的列表 ( )Y coordinate
2 回答
莫回无
TA贡献1865条经验 获得超7个赞
这样的事情应该工作:
var rebarUniqueL = rebarUnique .GroupBy(x => x.MRebar.Number) .Select(x => x.OrderBy(y => y.Point2d.Y).First()) .ToList();
陪伴而非守候
TA贡献1757条经验 获得超8个赞
rebarUnique.OrderBy(x => x.Point2d.Y) // Order the items by Y
.GroupBy(x => x.MRebar.Number) //Then group them by number, within each group the items are still sorted by Y
.Select(g => new {Number = g.Key, Item = g.First()) // get lowest Y for each number
.ToList();
输出:
Number Item
1 {{Number: 1, Type: 1, Fi: 12}, (0,0)}
2 {{Number: 2, Type: 1, Fi: 12}, (15,18)}
3 {{Number: 3, Type: 1, Fi: 12}, (25,34)},
- 2 回答
- 0 关注
- 187 浏览
添加回答
举报
0/150
提交
取消