-1
我使這個函數返回一個文本文件中的兩個座標和一個名字。一切正常,但是當我嘗試在另一個函數中使用這些座標時,我似乎得到兩個integers
而不是doubles
。以下是使用getter時的實際代碼和輸出。從輸入文件一個C#文件流函數,它應該返回一組雙重座標
實例:
delfshaven 51.9229006954, 4.43681055082
delfshaven 51.9229377766, 4.43726467466
代碼:
public void ReadCoords(string path, string naam)
{
string line;
int endname;
int endfirstcoord;
int i;
string name;
string coord1;
string coord2;
double north, east;
var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
using (StreamReader reader = new StreamReader(fileStream, Encoding.ASCII))
{
while (!reader.EndOfStream)
{
line = reader.ReadLine();
if (line != "")
{
i = 0;
while (line[i] != ' ')
{
i++;
}
endname = i;
name = line.Substring(0, i);
i++;
if (naam == name)
{
while (line[i] != ',')
{
i++;
}
endfirstcoord = i;
coord1 = line.Substring(endname + 1, i - 1 - (endname));
coord2 = line.Substring(i + 2, line.Length - (i + 2));
north = double.Parse(coord1);
east = double.Parse(coord2);
deelgemeente.Add(new PointLatLng(north, east));
}
}
}
}
}
輸出:
{Lat=519226886783, Lng=443421830655}
{Lat=519227198819, Lng=443459846581}
{Lat=51922824973, Lng=443591425503}
{Lat=519228427681, Lng=443610117779}
{Lat=519229006954, Lng=443681055082}
預先感謝。
請顯示您的輸入文件。 –
你在哪裏爲生成的'PointLatLng'對象生成字符串輸出?使用您的代碼生成對象適用於我。覆蓋'ToString'返回如下內容:'return string.Format(「{{Lat = {0},Lng = {1}}}」,Lat,Lng);'輸出也是正確的。 – Streamline