从text读内容存放二维数组的问题。急

right89757 right89757 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
0, 40.123, -1.231, 10.59,
1, 40.230, -1.242, 10.51,
2, 40.235, -1.2425, 0,
3, 40.545, -1.9483, 10.35,
4, 40.015, -1.0473, 11.00,
text文件中存放这样一组数据。运行时输入两个点(例如0,1),计算这两个点的距离。
我先把上述内容存放在list中,然后split存放在二维数组Coor。
可是现在运行有错误,不知道错哪了。
错误提示:未经处理的异常: system.IndexOutOfRangeException:索引超出的数组范围

static void Main(string[] args)
{

//string path=@"E:\nottingham\study\PRG\Projects\distance_P2P\distance_P2P\Coordinate.txt";
//string[] readText = File.ReadAllLines(path);
//Console.WriteLine("Point Latitude Longitude Evelation");
//foreach (string s in readText)
//{
// Console.WriteLine(s);
//}

// string[][] Coor; //存放坐标的二维数组
// Coor = new string[5][];

List<string[]> list = new List<string[]>();
TextReader tr = new StreamReader(@"E:\nottingham\study\PRG\Projects\distance_P2P\distance_P2P\Coordinate.txt");

int line_total = 0; //总行数
while (tr.ReadLine() != null)
{
line_total++;
}
Console.WriteLine(line_total); //先输出一下总行数

string rd = "";
while ((rd = tr.ReadLine()) != null)
{
string[] row = tr.ReadLine().Split(',');
string[] col = new string[row.Length];
for (int i = 0; i < row.Length; i++)
{
col[i] = Convert.ToString(row[i]);

}
list.Add(col);

}

string[][] Coor = list.ToArray();
Console.WriteLine(Coor[0][0]);

}
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
right89757
C# 111,128 成员 642,536 内容