有人可以告诉我我缺少什么,该类从文本文件中读取值并应该将它们存储以供其他用途,我可以看到这些值
Console.Write(eachCell[0])
但我无法保存这些值。我试过使用
string[]
,List<string>
但没有运气。它应该将读取的值存储到列表或数组中,但到目前为止还不是。控制台上没有任何显示。
class test
{
public void tryOut()
{
#region file.read
try
{
string fileLocation = @"shelfInfo.txt";
List<string> cells = File.ReadAllLines(fileLocation).ToList();
aray(cells);
}
catch
{
new FileNotFoundException();
}
#endregion
}
public void aray(List<string> cells)
{
string[] t = new string[20];
string[] k = new string[20];
string a = "", b = "", c = "", d = "";
int i = 0;
foreach (string cell in cells)
{
string[] eachCell = cell.Split('@', '\t', '\n');
a = t[0] = eachCell[0].ToString(); //Consol.Write on eachCell directly shows the right values.
b = t[1] = eachCell[1].ToString();
c = t[2] = eachCell[2].ToString();
d = t[3] = eachCell[3].ToString();
for (; i < eachCell.Length; i++)
{
k[i] = a; //should store the values from eachCell
}
}
Console.Write(" " + a + " " + b + " " + " " + c + " " + d); //means the value are being receivedbut no stored
}
}
// contents of text file
//A11[1]@ A12[0]@ A13[1]@ A14[1]@
//A21[1]@ A21[1]@ A23[0]@ A24[0]@
//A31[1]@ A32[0]@ A33[1]@ A34[1]@
//A41[1]@ A41[1]@ A43[0]@ A44[0]@
我也很感激有关异常处理的任何提示。