I have a table (HallPlan) with fields:
Row, Seat, Width, Height, X, Y
And grouped collection by Y:
var ordered = hallPlans.GroupBy(s => s.Y).OrderBy(o => o.Key);
now I want to select max X from all minimum X for each group. For example ordered contains three groups, we have:
first group contains 3 records with X coordinates: 15, 50, 80;
second group contains: 16, 50,80;
and last group contains: 15, 40, 60;
select all min from each groupes: 15, 16, 15
and select max from the above: 16.
How can I do this with LINQ?
Thanks.
You can use the
MinandMaxfunctions.groups.Select(g => g.Min(h => h.X))will select the minimunHallPlan.Xfrom each group, and.Max()will then return the biggest value of those.