On Mon, 9 Jan 2006 22:20:02 -0800, "Baileys"
<Ba*****@discussions.microsoft.com> wrote:
Hi Joel,
a little "behind-the-scenes" might further clarify this: the C#-compiler
translates your using-block into a try-finally block containing the original
statements inside the using block
With this in mind, I'm surprised that 'using' is preferred over
try/finally. Yes, it looks simpler for opening one file...IF the file
open or subsequent ops are guaranteed not to generate an exception.
But if an exception is generated, isn't it better to have explicit
handlers in the finally block?
Also multiple file opens seem more awkward with 'using' statements.
I know that you could add multiple opens to one 'using' but I'm not
sure if the exact handling if, say, file #3 out of 5 generates an
exception. I would imagine that the compiler generates code that
knows to close/dispose just the first two files. But perhaps for that
reason, I've seen experts write nested 'using' blocks. Not pretty.
Couldn't the mutiple opens be more gracefully handled in a try-finally
block?