根据此链接(已发布):http:
//msdn.microsoft.com/en-us/library/s6938f28 (VS.80).aspx
按值传递引用类型如下所示。引用类型 arr 按值传递给 Change 方法。
除非为数组分配了新的内存位置,否则任何更改都会影响原始项目,在这种情况下,更改完全是该方法的本地更改。
class PassingRefByVal
{
static void Change(int[] pArray)
{
pArray[0] = 888; // This change affects the original element.
pArray = new int[5] {-3, -1, -2, -3, -4}; // This change is local.
System.Console.WriteLine("Inside the method, the first element is: {0}", pArray[0]);
}
static void Main()
{
int[] arr = {1, 4, 5};
System.Console.WriteLine("Inside Main, before calling the method, the first element is: {0}", arr [0]);
Change(arr);
System.Console.WriteLine("Inside Main, after calling the method, the first element is: {0}", arr [0]);
}
}
最后,有关更深入的讨论,请参阅 Jon Skeet 在此问题中的帖子:
在 C# 中通过引用或值传递对象