点   纬度    经度     海拔
0,  40.123, -1.231, 10.59
1,  40.230, -1.242, 10.51
2,  40.235, -1.2425, 0text文件中存放这样一组数据。运行时输入两个点(例如0,1),计算这两个点的距离。
怎么从text读内容存到二维数组暂时只写成这样。。 static void Main(string[] args)
        {
            string[][] Coor;    //存放坐标的二维数组
            Coor = new string[3][];
            TextReader tr = new StreamReader(@"E:\nottingham\study\PRG\Projects\distance_P2P\distance_P2P\Coordinate.txt");
            
            string rd="";
            while ((rd = tr.ReadLine()) != null)
            {
                string[] row = rd.Split(',');
                
            }
            
        }

解决方案 »

  1.   

    File.ReadAllLines("")
    再split分割
      

  2.   

    是先把所有行读进来么?
    split分割是以数据为单位还是整行?
      

  3.   

    怎么split成那个二维数组的格式
      

  4.   

    foreach(string s in File.ReadAllLines(""))
    {
     string[] arr=s.Split(',');}
      

  5.   

    string[] rows = File.ReadAllLines(@"E:\nottingham\study\PRG\Projects\distance_P2P\distance_P2P\Coordinate.txt");
    string[][] values = new string[rows.Length][];
    for (int i = 0; i < rows.Length; i++)
    values[i] = rows[i].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
    //以下是输出各元素的值
    for (int i = 0; i < values.Length; i++)
    {
    for (int j = 0; j < values[i].Length; j++)
    Console.Write(values[i][j] + "    ");
    Console.WriteLine();
    }
      

  6.   

     string[] temp = System.IO.File.ReadAllLines("E:\\aaa.txt", System.Text.Encoding.GetEncoding("gb2312"));
                Dictionary<int, product> dic = new Dictionary<int, product>();
                foreach (string s in temp)
                {
                        string[] pInfo = s.Split(',');
                        int id = int.Parse(pInfo[1]);
                        if (!dic.ContainsKey(id))
                        {
                            product p = new product();
                            p.id = id;
                            p.name = pInfo[2];
                            p.count = int.Parse(pInfo[3]);
                            p.res = pInfo[4];
                            dic.Add(id, p);
                        }
                }
                foreach (int i in dic.Keys)
                {
                    product p = dic[i];
                    Console.WriteLine("Id:{0},name:{1},count:{2},res:{3},goodproductNo:{4},badproductNo:{5}", p.id, p.name, p.count, p.res, p.goodproductNo, p.badproductNo);
                }
      

  7.   

    其实那个行末是没有comma的,我写错了。。不过还是感谢,顺便可以学习一下有comaa的写法