0

If I have a function that takes a ref argument like:

void Foo(ref int i, int b, int c){
    i = b + c;
}

and I want to call that function with the ref int i argument determined conditionally:

int q, r;
bool bTest;
//...
if (bTest)
{
    bar(ref q,1,2);
}
else
{
    bar(ref r,1,2);
}

is it possible to locally declare something like a pointer or reference type to q/r and then pass that to bar?
Coming from c++:

    int q, r;
    bool bTest;
    //...

    int *pI;
    if (bTest)
    {
        pI = &q;
    }
    else
    {
        pI = &r;
    }
    bar(*pI,1,2);

Edited by Jsplinter

2
Contributors
1
Reply
4
Views
5 Years
Discussion Span
Last Post by darkagn
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.