C# 为点类分配值时出现问题

  • 本文关键字:问题 分配 c# point
  • 更新时间 :
  • 英文 :


我在为点类分配整数时遇到困难。我有一个坐标类列表,其中包含一个整数的 XY 值(分别为 XpYp(。整数类型Int32,并使用以下命令从string转换为double,然后转换为integer

X = double.Parse(setX, System.Globalization.CultureInfo.InvariantCulture);

列表中的最小X值和Y值在分配给点之前会从每个坐标中扣除。检查显示计算正确执行,但在点中值都是错误的。我想知道我使用 points[n] 分配的方式是否存在问题,或者是否有更好的方法来创建点以绘制到多边形?抱歉,生成坐标类的过程相当长,所以我省略了它,但如果您需要更多信息,请告诉我。

Point[] points = new Point[coords.Count];
int n = 0;
foreach (var i in coords)
{
    //These calculations are working fine: 
    int Xp = i.Xplt - minX;
    int Yp = i.Yplt - minY;
    //However when I assign to a new point. The calculation is wrong returning 0's and the incorrect result 
    points[n] = new Point(Xp, Yp);
    n = +1;
 }

在此行

n = +1;

你可能

n += 1;

最新更新