I am trying to write a division method, which accepts 2 parameters.
public static decimal Divide(decimal divisor, decimal dividend)
{
return dividend / divisor;
}
Now, if divisor is 0, we get cannot divide by zero error, which is okay.
What I would like to do is check if the divisor is 0 and if it is, convert it to 1. Is there way to do this with out having a lot of if statements in my method? I think a lot of if()s makes clutter. I know mathematically this should not be done, but I have other functionality for this.
For example:
if(divisor == 0)
{
divisor = 1;
}
return dividend / divisor;
Can it be done without the if()
statement?