Re: Can't use using in method???

From: William Ryan eMVP (bill_at_NoSp4m.devbuzz.com)
Date: 03/31/04


Date: Tue, 30 Mar 2004 19:29:36 -0500

Julie:

No, it's not legal the way you are using it (pardon the pun). using at the
top of a class does "importing" of namespaces for you. If you use it inside
a class it takes care of disposing of the object when you are done with it:

This isn't ok at the topof a module:

using SqlDataReader;

however, inside a method this is legal:

using(SqlConnection = new SqlConnection(ConnectString)){//whatever}

using System.Data.SqlClient; //totally ok at the top of a class.

So using has two different uses.

HTH,

Bill
"Julie" <julie@nospam.com> wrote in message
news:406A0E34.ACCBB3A6@nospam.com...
> This isn't legal???
>
> class Something
> {
> public void OrOther()
> {
> using System; // error!
> }
> }
>
> From what I can tell from the docs, using is only usable at the global
level or
> within an enclosing namespace, but not within a method --
>
> If that is truly the case, then I put using on my short list of directives
to
> *not* use...



Relevant Pages

  • stave back to being the wanna be stalker that cant find the target
    ... they were laid (pardon the pun) to rest when I came back in ... yet another pun, but I keep grinding the organ, and you keep up the ... alleged dyslexia, Morkie...If you did, the welfare checks would stop! ... Usenet Zone Free Binaries Usenet Server ...
    (rec.radio.amateur.policy)
  • Memorandum to Morkie Moron
    ... they were laid (pardon the pun) to rest when I came back in ... yet another pun, but I keep grinding the organ, and you keep up the ... alleged dyslexia, Morkie...If you did, the welfare checks would stop! ... can stay at home, stuff your face with hot dogs, beer and chips, and ...
    (rec.radio.amateur.policy)
  • Re: When To Use Imports And When To Use The Full Namespace Path ?
    ... When I stated "imported every thing" I was referring to all 120+ namespaces ... in the framework. ... example) or use an Alias. ... but importing all namespaces used in the class makes ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Not too shabby...
    ... I vaguely recall a splinter group (pardon the pun) that ...
    (rec.woodworking)
  • Re: Bummer
    ... >> How did he manage to hit you in the rear (pardon the pun), ...
    (uk.rec.motorcycles)