15,607,737 members
See more:
Hi,
I have a MapPoint List that has X and Y coordinates. I would like to find in that list, the smallest X and Y, the highest Y and the smallest X, the highest X and Y and then the smallest Y and the highest X (I need to get corner points). Does anyone know how to sort List so that I have it so sorted? I know how to make it depend only on X or Y.

What I have tried:

C#
```ReadOnlyPointCollection pts = linieStrany.Points;
var mapPointList = pts.ToList();
var serazenySeznam=mapPointList.OrderByDescending(o => o.X).ToList();```

Don't know how to do it? Maybe it's done in a completely different way...

Thank you

David
Posted
Updated 6-Jun-22 0:56am

## Solution 1

Look at the Max and Min methods:
Enumerable.Max Method (System.Linq) | Microsoft Docs[^]
Enumerable.Min Method (System.Linq) | Microsoft Docs[^]

If you want the corner points that enclose all points, then all you need are min x, min y, max x, and max y: the two corners (minX, minY) and (maxX, maxY) enclose all points.

v2
dejf111 6-Jun-22 7:38am
Thank you
OriginalGriff 6-Jun-22 7:45am
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 OriginalGriff 105 Chris Copeland 75 Richard MacCutchan 40 merano99 30 Maciej Los 30
 OriginalGriff 2,216 Richard MacCutchan 983 Graeme_Grant 640 Dave Kreskowiak 621 CHill60 275

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900