Variable scope and the 'using' statement in .NET

Posted by pete the pagan-gerbil on Stack Overflow See other posts from Stack Overflow or by pete the pagan-gerbil
Published on 2011-01-09T12:45:20Z Indexed on 2011/01/09 12:53 UTC
Read the original article Hit count: 182

Filed under:
|

If a variable is at class level (ie, private MyDataAccessClass _dataAccess;, can it be used as part of a using statement within the methods of that class to dispose of it correctly?

Is it wise to use this method, or is it better to always declare a new variable with a using statement (ie, using (MyDataAccessClass dataAccess = new MyDataAccessClass()) instead of using (_dataAccess = new MyDataAccessClass()))?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about using