Casey Crookston Casey Crookston - 8 days ago 5
C# Question

Refactor a multi-layered if-then

Looking for someone to proofread my logic. I inherited a method that contains this:

If (a || b)
{
doTaskOne();
}
else
{
if (c)
{
doTaskOne()
}
doTaskTwo()
}


Could this be simplified like this?

If ((a || b) || c))
{
doTaskOne();
}
else
{
doTaskTwo()
}

Answer
if (a || b || c) doTaskOne();
if (!a && !b) doTaskTwo();

Is this what you're looking for?