所以我的方法理论上应该有效,我只是没有得到我的预期结果。
我有一个函数可以创建一个新的 TextReader 类,从我的文本文件中读取一个字符(int)并将其添加到一个列表中。
文本文件数据如下所示 (48 x 30):
111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111100000000001111111111000000111111111 111111110000000000000000000000000000000011111111 100000000000000000000000000000000000000001111111 000000000000001111111111111111111111000001111111 100000001111111111111111111112211221000001111111 100000111111122112211221122111111111000001111111 111111111221111111111111111112211110000011111111 111112211111111111111111111111111100000111221111 122111111111111122111100000000000000001111111111 111111111111111111100000000000000000011111111111 111111111111111111000000000000000001112211111111 111111111111221110000001111110000111111111111111 111111111111111100000111112211111122111111111111 111111112211110000001122111111221111111111111111111122111111000000011111111111111111112211221111 111111110000000011111111112211111111111111111111 111111000000001111221111111111221122111100000011 111111000000011111111111000001111111110000000001 111111100000112211111100000000000000000000000001 111111110000111111100000000000000000000000000011 111111111000011100000000000000000000000011111111 111111111100000000000000111111111110001111111111 111111111110000000000011111111111111111111111111 111111111111100000111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111111111000000011111111111000001111111110000000001 111111100000112211111100000000000000000000000001 111111110000111111100000000000000000000000000011 111111111000011100000000000000000000000011111111 111111111100000000000000111111111110001111111111 111111111110000000000011111111111111111111111111 111111111111100000111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111111111000000011111111111000001111111110000000001 111111100000112211111100000000000000000000000001 111111110000111111100000000000000000000000000011 111111111000011100000000000000000000000011111111 111111111100000000000000111111111110001111111111 111111111110000000000011111111111111111111111111 111111111111100000111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111成11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111成
我的方法如下:
private void LoadReferenceMap(string FileName)
{
FileName = Path.Combine(Environment.CurrentDirectory, FileName);
List<int> ArrayMapValues = new List<int>();
if (File.Exists(FileName))
{
// Create a new stream to write to the file
using (TextReader reader = File.OpenText(FileName))
{
for (int i = 0; i < 48; i++)
{
for (int j = 0; j < 30; j++)
{
int x = reader.Read();
if (x == -1)
break;
ArrayMapValues.Add(x);
}
}
}
level.SetFieldMap(ArrayMapValues);
}
}
回报:
正如您所看到的,一旦到达第一行的末尾,Read() 返回 13,然后返回 10,然后再继续下一行?