Can someone explain why these nested `using` is different from the ordinary one?
How is this:
different from:
5 Replies
it's not
I think they are. I remember that some streams were not behaving correctly if I don't use the second one. I think they have different scopes?
the only change is no braces for the first using statement, which is fine as long as you only have one statement in it (which you do in this example, another using)
it's the same rules for other statements like
the reason you can do is exactly for the same reason you can do
it is not special behavior, it is just that you can remove the braces for an embedded statement
it works identically to the version with the braces
not directly related but using declarations may be more convenient for you regardless unless you actually need to control the lifetime of the object within the method
will automatically dispose the object at the end of the scope it's declared in