【发布时间】:2020-06-28 10:51:56
【问题描述】:
我想将 CSV 值添加到数组中,但出现此错误:
索引超出了数组的范围。
这是我的代码:
try
{
using (var reader = new StreamReader(@"/Users/ghost/Desktop/test.csv"))
{
List<string> listA = new List<string>();
List<string> listB = new List<string>();
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(';');
listA.Add(values[0]);
listB.Add(values[1]);
}
}
}
catch (Exception e)
{
Console.WriteLine("The File could not be read:");
Console.WriteLine(e.Message);
Console.ReadLine();
}
【问题讨论】:
-
其中一行读取没有 ;在里面。 (这不是这样做的方法)
标签: c# arrays .net visual-studio csv