using statement, why just a single type? 
Author Message
 using statement, why just a single type?

This is just a minor annoyance but why is the using statement limited to
creating instances of one type only?
Example:

// Not allowed
using (Type1 t1 = new Type1(), Type2 t2 = new Type2())
{
    // do some stuff...

Quote:
}

// Must do this instead
using (Type1 t1 = new Type1())
{
    using (Type2 t2 = new Type2())
    {
        // do some stuff...
    }

Quote:
}

I just think the first version is so much easier to read....

/Patrik



Sun, 19 Sep 2004 16:56:47 GMT  
 using statement, why just a single type?
or even with no parameters where it cleans up everything in the scope

using
{
    Blah blah = new Blah();
    blah.DoIt1();

    Blah blah = new Blah();
    blah.DoIt2();

Quote:
}

> This is just a minor annoyance but why is the using statement limited to
> creating instances of one type only?
> Example:

> // Not allowed
> using (Type1 t1 = new Type1(), Type2 t2 = new Type2())
> {
>     // do some stuff...
> }

> // Must do this instead
> using (Type1 t1 = new Type1())
> {
>     using (Type2 t2 = new Type2())
>     {
>         // do some stuff...
>     }
> }

> I just think the first version is so much easier to read....

> /Patrik



Mon, 20 Sep 2004 00:00:12 GMT  
 using statement, why just a single type?

Quote:

> This is just a minor annoyance but why is the using statement limited to
> creating instances of one type only?

I don't know. Fixed blocks are like this too. I do this:

Quote:
> using (Type1 t1 = new Type1())
> using (Type2 t2 = new Type2())
> {
>     // do some stuff...
> }

There is a slight potential for confusion, but it saves a level of
indentation which can make code less readable.

--
Dave O'Hearn



Mon, 20 Sep 2004 01:23:03 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. why no braces for single statement blocks?

2. re : why no braces for single statement blocks?

3. PRB: using statement can only contain a singe type (CS1044)

4. Using types in a different assembly given that the type may be used or not used

5. Converting Delphi type SINGLE to C float type

6. Single (VB type) to Float (VC type) precision resolution

7. handling single quotes in database statements

8. Why can't overload type cast to base type (object)

9. why does this if statement fail ?

10. C# version of VB6 Type statement

11. C# Strange if{} statement behavior, why?

12. Single array, multiple types/names

 

 
Powered by phpBB® Forum Software