Variable scope and the 'using' statement in .NET
- by pete the pagan-gerbil
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()))?