任何人都可以向我解释为什么这段代码会更改Matrix内部数组:
public Labyrinth(int width, int height)
{
baseMatrix = new char[width][];
for (int i = 0; i<baseMatrix.Length; ++i)
{
baseMatrix[i] = new char[height];
}
mod(baseMatrix[0]);
}
void mod(char[] x)
{
x[0] = 'a';
}
这并没有改变任何事情:
public Labyrinth(int width, int height)
{
baseMatrix = new char[width][];
for (int i = 0; i<baseMatrix.Length; ++i)
{
baseMatrix[i] = new char[height];
}
baseMatrix.Select(x => x[0] = 'a');
}
我不明白,select和函数都采用char []元素,我认为这是传递值,然后x [0]应该在两种情况下修改,我错了吗?