Definition of functions in C #
Modifier return type function name ( parameter list )
About return types
1: If the return type of the function is not void, a return statement must be returned in the body of the function, and the type of the return value is either the return type of the function or it can be implicitly converted to the return type of the function. Otherwise, you need to cast to the return type of the function.
2: If the return type of the function is not void, then in the execution of the function body, each outlet must have a return statement to be returned value.
About parameters
1: The parameter is in the form: type parameter name.
2: Similar to C + +,Java , the parameters for the base data type are passed with the value. However, similar to C + + , you can use special methods to "reference" the parameters of the base data type by using the keyword ref or out to decorate the parameter (in C + + using the " & " notation, while in Java There is no such mechanism.)
Such as:
Publicvoid changevalue (ref int m, out int n)
Note the difference:ref requires that the parameter must already be initialized outside the function, while out requires reinitialization before the parameter is first used in the body of the function.
In addition, when the function is called, the argument list is also accompanied by the ref or out keyword.
3: Variable parameter
mutable parameters in C # are arrays decorated with the params keyword, and the mutable parameter must be the last parameter in the argument list.
such as:intsumvals (params int[] vals)
Functions in C #