我正在尝试将文本文件读入二维数组。但是我得到一个错误
输入字符串的格式不正确。
我检查了文本文件,一切正常,但我不明白为什么会发生这个错误?
int[,] numberMatrix = new int[10, 10];
string[] split = null;
for (int rowCount = 1; rowCount < 11; rowCount++)
{
int[] temp1DArray = new int[10];
string fileLocation = "C:\\Week10\\one.txt";
string textFile = File.ReadAllText(fileLocation);
for (int columnCount = 1; columnCount < 11; columnCount++)
{
string delimStr = " ";
char[] delimiter = delimStr.ToCharArray();
//string fileLocation = "C:\\Week10\\1-100.txt";
//string textFile = File.ReadAllLines(fileLocation);
for (int x = 0; x <= 10; x++)
{
split = textFile.Split(delimiter, x);
}
}
for (int rowCount1 = 1; rowCount1 < 11; rowCount1++)
{
for (int columnCount = 1; columnCount < 11; columnCount++)
{
numberMatrix[rowCount1 - 1, columnCount - 1] =Convert.ToInt32(split.ElementAt(columnCount - 1));
}
}
}
for (int rowCount = 10; rowCount > 0; rowCount--)
{
for (int columnCount = 10; columnCount > 0; columnCount--)
{
Console.WriteLine(numberMatrix[rowCount - 1, columnCount - 1]);
}
}
}