static List<List<Point>> GetClusters(List<Point> points, double eps, int minPts)
        {
            if (points == null) return null;
            List<List<Point>> clusters = new List<List<Point>>();
            eps *= eps; // square eps
            int clusterId = 1;
            for (int i = 0; i < points.Count; i++)
            {
                Point p = points[i];
                if (p.ClusterId == Point.UNCLASSIFIED)
                {
                    if (ExpandCluster(points, p, clusterId, eps, minPts)) clusterId++;
                }
            }
            // sort out points into their clusters, if any
            int maxClusterId = points.OrderBy(p => p.ClusterId).Last().ClusterId;
            if (maxClusterId < 1) return clusters; // no clusters, so list is empty
            for (int i = 0; i < maxClusterId; i++) clusters.Add(new List<Point>());
            foreach (Point p in points)
            {
                if (p.ClusterId > 0) clusters[p.ClusterId - 1].Add(p);
            }
            return clusters;
        }
画像のクラスターを取得するために上記の方法を使用していますが、実行すると
エラーが発生します:  シーケンスに要素が含まれていません:
int maxClusterId = points.OrderBy(p => p.ClusterId).Last().ClusterId;
そのエラーを解決するにはどうすればよいですか?
私はから変更しようとしています:
int maxClusterId = points.OrderBy(p => p.ClusterId).Last().ClusterId;
に :
int maxClusterId = points.OrderBy(p => p.ClusterId).LastOrDefault().ClusterId;
しかし、エラーは次のとおりです。
オブジェクト参照がオブジェクト インスタンスに設定されていません。