This is a question I have asked myself many times in the past as I nested using statements 5 deep.
Reading the docs and finding no mention either way regarding other disposables instantiated within the block I decided it was a good Q for SO archives.
Consider this:
using (var conn = new SqlConnection())
{
var conn2 = new SqlConnection();
}
// is conn2 disposed?
No they are not. Only the set of variables explicitly listed in the using clause will be automatically disposed.
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