A function is an important part in any language, no matter what kind of program is composed of more or less functions. The use of a function, divided into declarations and calls two steps.
- Declaration of a function
Static return type function name (argument list) { function body}
The parameter list is in the form: parameter type parameter name, parameter type parameter name, ...
function names, argument lists, return types, function bodies are the 4 basic components of a function, where the function name and return type are the two parts that are indispensable to the function.
Function name (parameter list);
The call to the function can be reached.
When a function is called: The calling function uses a parameter type and quantity and the function definition uses the type and number of parameters to keep one by one corresponding.
- Formal parameters and arguments
Parameter: The argument used in the function definition.
Arguments: Parameters that are used when a function is called.
The formal parameter and the argument are two independent existence, the parameter change does not affect the actual parameter the original value, after the formal parameter obtains the value which the argument passes, the actual parameter change also does not affect the parameter the numerical value.
Static void Main () { int11; Console.Write (Numadd (A, b)); Static int numadd (intint y) { return x + y;}
In the above example, A and B are arguments, and x and y are formal parameters, and no matter how the A,B,X,Y4 variable changes, the values will not be affected by the number of variables passed.
How to use C # functions