I have a value that cannot go below a set value or above another set value. I have written a method to handle this for me. I am showing you two version of this same method written slightly different. One with multiple if
statements and one with an else if
tree. Both return the same result. But is one better than the other for some reason? Or (no kidding) is there a third, better way?
double Constrain(double low, double value, double high)
{
if (value < low)
return low;
else if (value > high)
return high;
else
return value;
}
double Constrain(double low, double value, double high)
{
if (value < low)
return low;
if (value > high)
return high;
return value;
}