Let's look at two concepts before you introduce them:Formal ParametersAndactual Parameters。
1. the formal parameter declaration is in the parameter list of the method, as in the following code, x and y are formal parameters.
2. An argument is an expression or variable used for the initial taxiing parameter, such as the following code. 5 and age are method arguments, 5 is an expression, and age is a variable of type int.
int age=; MethodName (5, age);
The method parameters in C # can be divided into: value parameter, reference parameter, output parameter and parameter array.
1 . Value parameter: pass the data to the method by copying The value of the argument to the formal parameter. When the method is called, the system follows: 1) Allocates space for the parameter in the stack, and 2) copies the value of the argument to the parameter. as follows.
Note: Do not confuse value types with value parameters, only arguments are the values of the arguments that are copied to the parameter, regardless of whether the argument type is a reference type or a value type.
2. reference parameter : the ref modifier must be used in method declarations and invocations.
Note: As a reference parameter, the system does not allocate memory for the number of shapes on the stack, and the parameter names of the parameters are aliases of the variables that are arguments, pointing to the same memory location as the arguments.
3. output parameters : Used to pass data from the method body to the calling code, you must use the Out modifier in both the declaration and the call.
Note: An output parameter must be assigned before it is called in the method body, meaning that any assignment outside the method body is meaningless.
4. parameter array : Use the params modifier before the data type.
1) Single value incoming method:
2) as a whole array of incoming methods:
Note: There can be only one parameter array in a method, and must be the last parameter of the parameter list.
Re-learning C # Series-01. Method Parameters