I have this code:
int someValue = 100;
if (x == 5)
{
if (someCondition)
{
return someValue;
}
return someValue / 12;
}
if (x == 6)
{
if (someCondition)
{
return someValue * 12;
}
return someValue;
}
As you see, someCondition is always the same, just the returned value differs. Is there a way to simplify this some more?
Let's see, what do you think of this?
int someValue = 100;
if (x == 5)
return someCondition ? someValue : (someValue / 12);
else if (x == 6)
return someCondition ? (someValue * 12) : someValue;
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