What I want to say is that the reason why -- ref and out confused me was that they did not seriously analyze the different actions it made for different types.
For value type.
The effect of using ref and out is almost the same as that of using pointer variables in C. It allows you to operate the original number directly, rather than the copy operation of the original number. For example:
Using
System;
Namespace consoleapplication4
{
///
/// Summary of class1.
///
Class class1
{
///
/// Main entry point of the application.
///
[Stathread]
Static void main (string [] ARGs)
{
Int A = 5;
Int B;
Squareref (Ref );
Squareout (Out B );
Console. writeline ("the in the main is:" + );
Console. writeline ("the B in the main is:" + B );
}
Static void squareref (ref int X)
{
X = x * X;
Console. writeline ("the X in the squareref is:" + x );
}
Static void squareout (Out int y)
{
Y = 10;
Y = y * Y;
Console. writeline ("the Y in the squareout is:" + y );
}
}
}
The result is -- 25 100 25 100.
In this way, it achieves the same effect as the pointer variable in C.