我在一个方法中有一个 char 数组, someObject 是通过引用 GetChars 方法传递的任意对象:
private void DoSomeStuff(ref Object someObject)
{
char[] chars = GetChars(ref someObject); // {'a','b','c','d'}
char[] ReversedChars = Reverse(chars); // {'d','d','b','a'}
//chars and ReversedChars are in the same order, although "ref" is not used
}
private char[] Reverse(char[] someChars)
{
Array.Reverse(someChars);
return someChars;
}
如果不通过引用传递,为什么 Array.Reverse 在另一种方法中会更改原始传递的 char 数组?