텍스트 파일을 2 차원 배열로 읽으려고합니다. 그러나 나는텍스트 파일을 2 차원 배열로 읽을 때 올바른 형식이 아닌 입력 문자열
의 오류가 발생합니다. 입력 문자열의 형식이 올바르지 않습니다.
나는 텍스트 파일을 검사했으며 이것이 모두 있어야하며이 오류의 원인을 알 수 없습니까?
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]);
}
}
}
오류가 40 행에 있음을 나타냅니다. – ProgrammingRookie
어느 것이 40 행입니까? :) –
파일 내용 및 예상 결과의 예제를 제공하십시오. –