how can i eliminate multiple number of return statements to one statement. example: i hav one if clause, the result of the if clause is true it will return 0. or return 1, the else of the same if contains another if clause. it has also the return value. how can i eleiminate this four return statement to one?
this is the program
if (IgC == true)
{
if (val1.ToUpper() == val2.ToUpper())
{
return 0;
}
else
{
return 1;
}
}
else
{
if (val1 == val2)
{
return 0;
}
else
{
return 1;
}
}
Here is my guess at the logic…
and with your now-posted update:
I avoid nesting ternary operators or check more than one condition with them, as that makes the code obscure really fast. It is not that the code gets any less efficient if you are more explicit, so the whole thing is solely about readability.
I try to weigh code length and visual complexity against expressiveness, and the if/ternary combination seems to be good middle ground for me.