I have a function such as this one:
public string MyFunction(int a, out int b)
{
var test = ""
b = 6;
return test;
}
and then on the receiving end:
int b = 0;
var testOutcome = MyFunction(3, b);
I wonder how to get the value of: b in this scenario?
something like:
var bOutcome = ....;
You get the out parameter from the method. Note that you also need to add the out keyword in the parameter signature of the method:
int b = 0; // initialization is redundant
string testOutcome = MyFunction(3, out b);
// b is initialized now
Although variables passed as out arguments do not have to be initialized before being passed, the called method is required to assign a value before the method returns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With