I am trying to write a separation method that takes 2 parameters.
public static decimal Divide(decimal divisor, decimal dividend)
{
return dividend / divisor;
}
Now, if divisor is 0, we get that we cannot divide by zero error, which is good.
What I would like to do is check if the divisor is 0, and if so, convert it to 1. Is there a way to do this without having many if statements in my method? I think a lot (if) creates a mess. I know that mathematically this should not be done, but for this I have other functions.
For example:
if(divisor == 0)
{
divisor = 1;
}
return dividend / divisor;
Can this be done without instructions if()?
Heinrich fröbe
source
share