我有一些問題,爲什麼C#不喜歡coordinates[j]
部分,我可以做些什麼。如何擺脫編譯錯誤:C#使用未分配的局部變量?
string[] lines = System.IO.File.ReadAllLines(@"C:\Users\sp\Dropbox\ProjectEuler\102\p102_triangles.txt");
string[] coordinates_str;
double[] coordinates; //Contains the coordinates for each line A1(x,y), A2(x,y), A3(x,y)
long ln = lines.Length;
Console.WriteLine("Length: " + ln.ToString());
for (int i = 0; i < ln; i++)
{
Console.Write(i);
Console.Write(lines[i]);
coordinates_str = lines[i].Split(',');
for (int j = 0; j < 6; j++)
{
coordinates[j] = Convert.ToDouble(coordinates_str[j]);
}
}
你還沒有在座標[]中分配任何空間...... – 2014-10-16 23:44:08