Are there any side effects of returning from inside a using() statement?
By : Clayton Kanemitsu
Date : October 18 2020, 11:12 AM
This might help you No, I think it's clearer this way. Don't worry, Dispose will still be called "on the way out" - and only after the return value is fully evaluated. If an exception is thrown at any point (including evaluating the return value) Dispose will still be called too. While you certainly could take the longer route, it's two extra lines that just add cruft and extra context to keep track of (mentally). In fact, you don't really need the extra local variable - although it can be handy in terms of debugging. You could just have:
Are there any side effects of returning from inside a foreach statement?