一个 C# 文件流函数,应该 return 一组双精度坐标

A C# filestream function, which should return a set of double coordinates

我将此函数设为 return 来自文本文件的两个坐标和一个名称。一切正常,但是当我尝试在另一个函数中使用这些坐标时,我似乎得到了两个 integers 而不是 doubles 。以下是使用 getter.

时的实际代码和输出

来自输入文件的示例:

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}

提前致谢。

感谢您的帮助。我得到了修复。由于我的本地笔记本电脑设置,出现了这个问题。将字符串转换为双精度时遇到问题。

north = double.Parse(coord1, CultureInfo.InvariantCulture);
east = double.Parse(coord2, CultureInfo.InvariantCulture);

而不是

north = double.Parse(coord1);
east = double.Parse(coord2);

已修复。