![](/img/trans.png)
[英]Can anyone tell me why this doesn't work to solve Problem 8 of Project Euler?
[英]I am trying to read information from a .csv and put it into an array in C#. Can anyone tell me why the code doesn't work?
编辑:通过评论解决
StreamReader sr = new StreamReader("Details.csv");
在文件中有
5 个用户名和 5 个密码,它们应该用逗号分隔,因为它们在 excel 的不同单元格中,但它们都放在一个单元格中
//reading in details
string[ , ] data = new string[hML, 3];
string[] tempArr = new string[3];
string lineIn = "";
for (int i = 0; i < hML; i++)
{
lineIn = sr.ReadLine();
tempArr = lineIn.Split(Convert.ToChar(","));
data[i, 0] = tempArr[0];
data[i, 1] = tempArr[1];
data[i, 2] = tempArr[2];
}
当它试图以逗号分割时,我得到一个“System.NullReferenceException:'对象引用未设置为 object 的实例。'”错误,我不知道这意味着什么
这意味着您正在尝试在初始化之前访问 object 如果我冒险猜测我会说它是 sr 变量,aa 在您发布的代码中没有声明它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.