我正在尝试为 Unity 编写一些 C# 代码,这些代码将从文本文件中读取,将每一行存储在字符串数组中,然后将其转换为 2D 字符数组。
错误发生在:
void ReadFile()
{
StreamReader read = new StreamReader(Application.dataPath + "/Maze1.txt");
int length = read.ReadLine().Length;
maze = new string[length, length];
line = new string[length];
while(!read.EndOfStream)
{
for (int i = 0; i <= length; i++)
{
line[i] = read.ReadLine();
}
for( int i = 0; i <= length; i++)
{
for( int j = 0; j <= length; j++)
{
maze[i,j] = line[i].Split(','); // <---This line is the issue.
}
}
}
}
我得到的确切错误是:
Cannot Implicitly convert type 'string[]' to 'string'
这个错误是什么意思,我该如何修复代码?