Given a situation like this:
using (var foo = CreateFoo()) {
if (foo != null) {
// do stuff
}
}
I would like to avoid the nested if. Sadly, the obvious solution is not possible because break does not work with using:
using (var foo = CreateFoo()) {
if (foo == null) {
break;
}
// do stuff
}
Is there a pattern to still avoid the additional indentation caused by the if != null
?
If you have sufficient control over the class returned from CreateFoo()
you could just implement a Null Object and return this instead of the actual NULL value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With