I have some methods which use if conditions, like this:
string method1()
{
bool x= Convert.ToBoolean(...);
bool y= Convert.ToBoolean(...);
if (x && y)
{
return " ";
}
if (!x && y)
{
return " ";
}
if (!y && x)
{
return " ";
}
if (!x && !y)
{
return "X";
}
return " ";
}
Thats my first method, now I have a similiar one, which has the same checks and the same boolean values, but returns other strings (not space or X). Whats an elegeant approach to solve this?
Thanks
The elegant approach is to refactor your code so that the boolean checks are in their own method that each of the other two methods can access, and then each method can return a string based on the result of the boolean check.
EXAMPLE