How to avoid OrderBy - memory usage problems
问题 Let's assume we have a large list of points List<Point> pointList (already stored in memory) where each Point contains X, Y, and Z coordinate. Now, I would like to select for example N% of points with biggest Z-values of all points stored in pointList . Right now I'm doing it like that: N = 0.05; // selecting only 5% of points double cutoffValue = pointList .OrderBy(p=> p.Z) // First bottleneck - creates sorted copy of all data .ElementAt((int) pointList.Count * (1 - N)).Z; List<Point>