好的 om 试图从一个 .txt 文件加载到一个整数数组到一个二维数组,但它让我“在 mscorlib.dll 中发生了类型为 'System.FormatException' 的未处理异常”我相信它与循环和也许会越界。但我对 c# 很陌生,所以我很难过。
它在“nRow[r] =Convert.ToInt32(row[r]);”上中断
protected void read_lvl()
{
IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("myFile.txt", FileMode.Open, FileAccess.Read);
using (StreamReader reader = new StreamReader(fileStream))
{ //Visualize the text data in a TextBlock text
while (!reader.EndOfStream)
{
//for each row
for (int i = 0; i < rows; i++)
{
//read in the line
string myLine = reader.ReadLine();
//take out the commas
string[] row = myLine.Split(',');
//convert to string to ints
int[] nRow = new int[row.Length];
for(int r=0; r<row.Length;r++){
nRow[r] =Convert.ToInt32(row[r]);
}
//feed back into the array
for (int j = 0; j < columns; j++){
myreadArray[i, j] = nRow[j];
}
}
}
}
}