This article describes the following:
Passing by value and passing by reference deep theory
Ref and out comparisons
Analysis on the application of parameters
Next, go on, "The 11th time: The confusion of parameters---the art of passing (on)"
4.2 Passing by value of reference type parameters
When the passed parameter is a reference type, it is a reference to the object that is passed and manipulated, which means that the method operation can change the original object, but it is worth thinking whether the reference or the pointer itself is passed by value. Therefore, we must have a clear understanding of the following two fundamental issues:
What is the difference between a reference type parameter and a by-value pass?
How does the string type behave as a special reference type, and how does it explain the specificity of the performance when passed by value?
First of all, we start from the basic understanding of the reference type parameters by value of the nature of the transfer, simply say the object as a parameter to pass, the execution is a copy of the object address, the operation is the copy address. This is essentially the same as the value-type parameter passed by value, and is passed by value. The difference is that the value of the value type is the type instance, and the value of the reference type is the reference address. Therefore, if the argument is a reference type, in the caller code, you can change the point of reference to make the original object's point change, as shown in the example:
Passing by value of reference type parameters
// FileName : Anytao.net.My_Must_net
// Description : The .NET what you should know of arguments.
// Release : 2007/07/01 1.0
// Copyright : (C)2007 Anytao.com http://www.anytao.com
using System;
namespace Anytao.net.My_Must_net
{
class Args
{
public static void Main()
{
ArgsByRef abf = new ArgsByRef();
AddRef(abf);
Console.WriteLine(abf.i);
}
private static void AddRef(ArgsByRef abf)
{
abf.i = 20;
Console.WriteLine(abf.i);
}
}
class ArgsByRef
{
public int i = 10;
}
}