Re: Why does using keyword require a new scope?

Discussion in 'ASP .Net' started by Herman Eldering, Aug 24, 2003.

  1. Hi,

    One problem I can think of is this case:

    {
    using AnyDisposableClass adc1 = new AnyDisposableClass();
    using AnyDisposableClass adc2 = new AnyDisposableClass();
    }

    The sequence can be important, and this is not visible from the code above.
    Therefor the current approach is clearer and I think it ways up to the fact
    that it needs a little more typing and a couple of indents.

    Herman Eldering

    "Dave Goldstein" <> wrote in message
    news:...
    > Why this nuisance:
    >
    > using(AnyDisposableClass adc = new AnyDisposableClass()) {
    > }
    >
    > when it could have been created this way:
    >
    > using AnyDisposableClass adc = new AnyDisposableClass();
    >
    > and then gets disposed when exiting scope?
    >
    > I believe C# allows anonymous scopes, so the same task could therefore
    > have been accomplished this way:
    > {
    > using AnyDisposableClass adc = new AnyDisposableClass();
    > }
    >
    > Any thoughts/responses? I find the using clause provided to be really
    > aesthetically displeasing and clumsy, as the layer of nesting is
    > completely unnecessary ecept for the implementation detail of when the
    > variable is actually initialized (i.e. scope could exit before the
    > variable is assigned; so what! null means do nothing!)
    >
    > To simplify things, a readonly/const could be implied or required by
    > such a use case.
    >
    > -d
    >
    Herman Eldering, Aug 24, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jip from Paris
    Replies:
    0
    Views:
    1,889
    Jip from Paris
    Aug 25, 2003
  2. Paul Opal
    Replies:
    12
    Views:
    927
    Paul Opal
    Oct 11, 2004
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,756
    Smokey Grindel
    Dec 2, 2006
  4. Replies:
    6
    Views:
    440
    Peter Otten
    May 10, 2007
  5. Hamilton, William

    RE: keyword checker - keyword.kwlist

    Hamilton, William, May 10, 2007, in forum: Python
    Replies:
    4
    Views:
    342
Loading...

Share This Page