Re: Can't use using in method???
From: William Ryan eMVP (bill_at_NoSp4m.devbuzz.com)
Date: 03/31/04
- Next message: Andrey Zvyagilskiy[MSFT]: "RE: Bug ?"
- Previous message: Scatropolis: "Re: test"
- In reply to: Julie: "Can't use using in method???"
- Next in thread: C# Learner: "Re: Can't use using in method???"
- Messages sorted by: [ date ] [ thread ]
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...
- Next message: Andrey Zvyagilskiy[MSFT]: "RE: Bug ?"
- Previous message: Scatropolis: "Re: test"
- In reply to: Julie: "Can't use using in method???"
- Next in thread: C# Learner: "Re: Can't use using in method???"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|