Monday, December 04, 2006

More missing things in C#

Something I'd like to add to my C# wish-list:

Why is it that when you use "using", you can only put a single parameter inside it. Often enough you need to use multiple resources at once, and want to get hold of them and release them at the same time. In such case you need to write something like this:


using (StreamReader reader = new StreamReader(inputFileName))
{
using (StreamWriter writer = new StreamWriter(outputFileName))
{

}
}


What I would really have liked better would be something like this:


using (StreamReader reader = new StreamReader(inputFileName),
StreamWriter writer =
new StreamWriter(outputFileName))
{

}


 Wouldn't you agree?

1 comment:

Anonymous said...

Not necessarily. For startes, I see nothing wrong with an intentionally unindented

using ( firstDisposable )
using ( secondDisposable )
{
...
}

What you suggest would be at best syntactic sugar of the not-really-meaningful type (unlike "using" itself, which has a very tangible effect on code clarity), and will only serve to complicate the grammatical structure of the language.