The so-called function is a code that has a separate function and can be reused by name. The function should pay special attention to the declaration before the call. and the declaration position of the function must be in the class.
The syntax for a function declaration is the static void function name ()
{
function body (implemented when function is called)
}
The scope of a function is a variable that is valid only within the curly braces that he defines. Variables of different scopes have independent memory space, and when the scope ends, the variable disappears from memory. The identifiers in the function are the places in the code that you need to name yourself. (C # must consist of a numeric letter underscore and cannot begin with a number, and translation errors will occur if the requirement is not met)
The next step is related to the function call, which must be declared before the call,
The first is to declare a function with parameters, the function syntax is the static void function name (argument list)
{
Comment Content
}
The parameter writing syntax is the data type parameter name, data type parameter name, ...
The function declaration syntax is public static void (formal parameter list) ... Parameters are the arguments used when the function is named
{
Comment Content
}
function call syntax function name (argument list) ... An argument refers to a parameter that is used when a function is called
When a function is called, the data of the argument is assigned to the parameter. (Arguments and parameters are independent of each other and do not affect)
The second is to declare a parameter with a return value
The return value of the function: The result that is produced after the run is finished. (return is used for returning results in the body of the function)
Use syntax: A return value or a variable or an expression. (When the function runs to the return statement, the function immediately returns the value after the return keyword, the result of a variable or an expression).
Call function syntax with return value: Function name (argument list)
The call to the function is an expression, and the return type is the same as the return type of the function declaration.
Through the full invocation of various functions can reduce the amount of code written, saving manpower and material resources, the most important thing is to reduce the error rate of code, and so on.
Function call related issues in C # code