Return statement
In BI# functions may return a value when they use the keyword
return
:
int Avg(int a, int b)
{
return (a + b) / 2;
}
The returned value must be of the same type as the function's type. In
the example above the function
Avg
is of type
int
and the
return
expression is of type
int
, too. The example also works if the
function type is
double
. In this case BI# converts the
int
expression automatically.
You can also use the
return
statement to leave a
void
function prematurely:
void PrintMessage(string message, int threshold)
{
if (threshold < 5)
{
return;
}
WriteLine(message);
}