我一直在努力去理解我在测试中必须理解的方法发生了什么,我很难弄清楚我得到的结果是什么原因,对f如何解释"方法有效,非常感谢
class Program {
static void Main(string[] args)
{
A b = new A(); b.y = b.x;
b.f(b.y); b.g();
Console.WriteLine(b.x[0] + " " + b.x[1]); // Prints 1 7
Console.WriteLine(b.y[0] + " " + (b.x[1] + b.y[1])); // 1 14
}
}
public class A {
public int[] x = {1, 2};
public int[] y;
public void f(int[] z)
{
z[1] += 5;
}
public void g()
{
A a = new A ();
a.x[0]++;
a.x[1]--;
}
}
Run Code Online (Sandbox Code Playgroud)
让我解释一下我理解的内容,通过创建数组并获取bx中的值,现在,当我们调用bf时,我们传递的方法是[1,2],现在,这就是我被卡住的地方,z似乎是by数组,所以它有[1,2]作为值,当方法将1添加到位置1中的元素(这是2)时,我得到[1,7]作为结果,当这个方法结束了,我的程序回到了main,不知何故,由AND Bx …