I know that using an SqlConnection inside a using block like below will close the connection at the end of the using block.
using (var connection = factory.NewSqlConnection())
{
//code
}
I want to know if an object that has a SqlConnection private field, and is used in a using statement will also close the connection like so:
using (var db = factory.NewDatabaseManager())
{
//code
}
public class DatabaseManager
{
private SqlConnection _connection;
public DatabaseManager(SqlConnection connection)
{
_connection = connection;
}
}