Passing on an out parameter

55 views Asked by At

Is there a way to pass on an out parameter?
I want the out parameter to not be set in the function itself, but to be set in a function I call.

I'm unsure if I just got the syntax wrong. Here is what I tried:

bool func1(out int additionalReturn)
{
    //sample code
    additionalReturn = 0;
    return true;
}
bool func2(out int additionalReturn)
{
    return func1(additionalReturn);
}
1

There are 1 answers

0
Daniel Bauer On

The keyword out in the calling function allows this. The syntax is like this:

bool func1(out int additionalReturn)
{
    //sample code
    additionalReturn = 0;
    return true;
}
bool func2(out int additionalReturn)
{
    return func1(out additionalReturn);
}