Methods
Method Declaration:
- the method name
- parameter types
- parameter order
- parameter names
- return type
- optional modifiers
//y and z are optional parameters.
static int AddSomeNumbers(int x, int y = 3, int z = 2)
{
return x + y + z;
}
Methods that do not return a value have a void return type
//using x and y inside the method is fine.
static void DeclareAndPrintVars(int x)
{
int y = 3;
Console.WriteLine(x + y)
}
Return Keyword: when return is invoked, the current method terminates and control is returned to where the method was originally called. The value that is returned by the method must match the method’s return type, which is specified in the method declaration.
Out Parameters: return can only return one value. When multiple values are needed, out parameters an be used.
Expression-Bodied Methods
static int Add(int</