On Jun 26, 3:42*pm, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
Why not just nest using statements?
I guess it just bothered me to have multiple indentations. Mostly for
preference reasons but also because if had two disposable objects used
within an area and then later changed that to 3 and only added a
single line within that region then the file would look like I made a
whole bunch of changes to many lines (unless I ignored whitespace
changes) because it had to indent a bunch of code. At what point does
the indentation become overwelming? 5, 6 or 7 levels?
Alternatively, you don't need the outer braces - using statements stack
nicely:
I wasn't aware of that but it makes sense since that's how the 'if'
statement works. I guess that's another personal thing but I always
make it a policy to never use 'if' statements without braces because
it scares me; the conditional code isn't properly contained with its
own scope and could spill out all over the place :) Also it was a
coding standard at my first job out of college and I guess it just
stuck with me.
You should be aware, by the way, that the using statement isn't like a
normal method - it's a language construct.
I guess that's why I figured they could have easily done whatever they
wanted when they first created C# since C++ doesn't have anything like
that. Was 'using' barrowed from VB6? Or was that a different using
because they didn't have the concept of dispose before .NET.