The value is passed, but the copy is passed, and the reference is passed, it is passed an address ~
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace ConsoleApplication10
{
Class Program
{
Static void Main (string [] args)
{
Int v = 42;
Int r = 42;
DoWorkVal (v );
DoWorkRef (ref r );
Console. WriteLine ("value transfer, result: {0 }! ", V );
Console. WriteLine ("passed by reference, the result is {0 }! ", R );
}
Static void DoWorkVal (int param)
{
Param + = 10;
}
Static void DoWorkRef (ref int param)
{
Param + = 10;
}
}
}
For the value transfer, only a copy is passed, so the void function does not return a value, so the original value remains unchanged when the v is output. for reference transfer, the address is passed in the past. Therefore, after the function DoWorkRef is called, the r will also change, so it will be + 10, so the output result is 52 ~
Author: "McDelfino"