c#将值分配给points类时出现问题

时间:2017-02-12 13:29:42

标签: c# point

我很难将整数分配给分数类。我有一个coords类列表,其中包含XY值的整数(分别为XpYp)。整数类型为Int32,并使用以下内容从string转换为double,然后转换为integer

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

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

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;
 }

1 个答案:

答案 0 :(得分:3)

在这一行

n = +1;

你可能会

n += 1;