Functions also refer to "methods".
Normal Functions
Defining / Using / Returning values
static <returnType> <FunctionName>() => <returnValue>; // expression-bodied functions
Parameters
Matching in order
Parameter array
1 static <returnType> <FunctionName>(<p1Type> <p1Name>, ..., params <type> [] <name>) 2 { 3 4 ... 5 6 return <returnValue>; 7 8 } 9 10 /* the same as fellowing: 11 <FunctionName>(<p1>, ..., <val1>, <val2>, ...)<val1>, <val2>, 12 and so on are values of type <type>, which are used to initialize the <name>array 13 */
Reference and Value Parameters
3 Types of Reference
in | specifies that this parameter is passed by reference but is only read by the called method |
ref | specifies that this parameter is passed by reference and may be read or written by the called method(must be signed) |
out | specifies that this parameter is passed by reference and is written by the called method (created by called function, treated as an unsigned parameter) |
Variables like strings and arrays are reference types and arrays can be returned with the ref keyword without a parameter declaration.
Tuple
It's designed for returning multiple values from the functions and most used when a program does not need a struct or more complicated implementations.
Parameters and Return Values vs. Global Data
Other Functions
Local Functions
Local functions allow you to declare a function within the context of another function. It can't be called from other functions contained in the class where the former function is defined.Structure Functions
Overloading Functions
To provide a uniform function model for various kinds of inputs to achieve a particular purpose.Delegate
storage of reference of functions1 //define a delegate 2 delegate <a define of function>; // now we have the delegate's name : <delegateName> 3 //use a delegate 4 <delegateName> <delegateVariableName>; 5 <delegateVariableName> = <FunctionName>; // this function is of the delegate's type 6 //now this <delegateVariableName> can be used as a "function" of its type