I am wondering what would be the the best practice for refactoring code that looks like this:
Where should the exit criteria should be set and what is the best practice
private static bool Foo()
{
bool result = false;
if (DoMehod1())
{
if (DoMehod2())
{
if (DoMethod3())
{
result = true;
}
else
{
Console.WriteLine("DoMethod3 Failed");
}
}
else
{
Console.WriteLine("DoMethod2 Failed");
}
}
else
{
Console.WriteLine("DoMethod1 Failed");
}
return result;
}
Thanks
The best structure for that code without changing what it does is this: