2017-02-12 82 views
0

我很難將整數分配給點類。我有一個包含XY值(分別爲XpYp)的整數的座標類列表。整數型是Int32和從使用stringdouble然後到達integer轉化:從被分配給一個點之前的各座標中扣除c#給點分配值的問題

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

回答

3

在此行中

n = +1; 

你可能包換

n += 1; 
+0

哎呀我無法相信我錯過了你的回答但由於 – alkey