So I have a function that does some validation. Let’s use this as an example:
int product = x * y;
if(product >= 20)
return product;
return 0;
}
If x times y is >= 20, then return the product, otherwise return 0, a failure condition.
In other languages I’ve been able to do something like (pseudocode, clearly):
log("It failed");
} else {
log("It worked, the answer is" + result);
}
I was able to run the function and store the result inside the if statement, and then test that result at the same time. Is this possible in C#/Unity? I’ve tried using a few different formats and none seem to work. Up til now I’ve been doing:
if(result == 0) {
log("It failed");
} else {
log("It worked, the answer is" + result);
}
Yes, it’s just an extra line of code, but for what I’m used to writing and for the sake of brevity, I prefer having tests like that in a simple single line assign-and-test format, if possible.
If not, no big deal. Just looking to remove some extra lines of code.
Thanks