Omer van Kloeten's .NET Zen

Programming is life, the rest is mere details

News

Omer van Kloeten's Facebook profile

Omer has been professionally developing applications over the past 8 years, both at the IDF’s IT corps and later at the Sela Technology Center, but has had the programming bug ever since he can remember himself.
As a senior developer at NuConomy, a leading web analytics and advertising startup, he leads a wide range of technologies for its flagship products.

Get Firefox


powered by Dapper 

.NET Resources

Articles :: CodeDom

Articles :: nGineer

Culture

Projects

Nested Using Statements

Just a quick note about the ongoing debate around nested using statements for multiple disposals.

True, you can do this:

using (StreamWriter w1 = File.CreateText("W1"))
    using (StreamWriter w2 = File.CreateText("W2"))
    {
        // code here
    }
but after working a lot on nGineer, I found that you can also do this:
using (StreamWriter w1 = File.CreateText("W1"),
    w2 = File.CreateText("W2"))
{
    // code here
}
which in my book, is a lot easier.

Comments

TrackBack said:

Nested using statements can soak up a lot of indentation so Eric Gunnerson has posted a tip on how to code them more succinctly. Taking his example, instead of this: using (StreamWriter w1 = File.CreateText("W1")) { using (StreamWriter w2 =...
# August 6, 2004 6:17 AM

TrackBack said:

# August 9, 2004 9:24 AM

Diego Mijelshon said:

Omer,
The problem with that solution is that it only works for IDisposables of the same type.
# August 9, 2004 10:23 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)