First, the use of parameters:
1. Value parameter (values Parameter)
Format: Method name (parameter type parameter name [, parameter type parameter name])
2. Reference parameters (Reference Parameter)
Format: Method name (ref parameter type parameter name [, ref parameter type parameter name])
3. Output parameters (out Parameter)
Format: Method name (out parameter type parameter name [, out parameter type parameter name])
The difference between the value parameter and the reference parameter and the output parameter:
The value of the argument in the 2.1 value parameter is not changed with the change of the parameter value;
Parameter values are not affected, and when an argument is passed to a formal parameter, it is allocated another part of the space on the stack. In this way, two parameter changes are not affected.
2.2 The values of arguments in the reference and output parameters change with the parameter value
(Formal parameters: The parameters specified in the definition function, which do not account for memory cells when function calls are not present. Only when a function call occurs does the parameter in the function be assigned an inner memory element. After the call is finished, the cells that are part of the parameter are also freed. The value of the argument is assigned to the parameter when called);
In the reference and output parameters, the argument allocates space in the stack. When an argument is passed to a parameter, the address is passed to the formal parameter, which is the passed-in pointer, and the argument changes as the parameter is changed.
Three, the reference parameter and the output parameter difference:
3.1 When using ref and out parameters, both the parameter in the method and the calling parameter require the ref or out keyword
3.2 The result of using the ref parameter is the same as the out parameter, except that ref needs to assign an initial value to the parameter in the calling method before the call. Out does not need to assign an initial value to the parameters in the calling method before the call, and the parameters are initialized in the actual method body.
C # Method passing parameters