我有一个积分列表。 List<Point> points = new List<Point>();
我想获得列表中 y 坐标的最大值,前提是它只扫描列表中具有特定 x 坐标的坐标。
例如:
我有这样的观点
(1,1)
(1,2)
(1,3)
(1,4)
(1,5)
(2,1)
(2,2)
(2,3)
(2,4)
(2,5)
我想找到 y 轴或 y 坐标的最大值,因为它只搜索以 2 作为 x 值的坐标。所以输出必须是(2,5)
最佳答案
使用 LINQ 获取具有最大 Y 坐标的点:
Point maximumPoint = points.First(p => p.X == 2 &&
p.Y == points.Max(po => po.Y));
或
Point maximumPoint = new Point(2, points.Where(p => p.X == 2).Max(p => p.Y));
关于c# - 获取有条件的 List Point 的最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21500766/