Avatar of ad5qa
ad5qa
Flag for United States of America

asked on 

Using around DAO Objects

I would like to know if this is a good practice or not.

In our code it is recommended to put using statements around our data access objects.

Most of the time it is in a button event scope anyway, it should just gc correct?
if (SOMETHING)
{
        using (CustomersDao dao = CustomersDao())
        {
		//Do something with the object
        }
}
    else
    {
         using (CustomersDao dao = CustomersDao())
         {
                //Do something with the object
         }
    }
}
 
 
WHY NOT
 
 
CustomersDao dao;
if (SOMETHING)
{
        dao = new CustomersDao();
        {
		//Do something with the object
        }
}
    else
    {
        dao = new CustomersDao();
        {
		//Do something with the object
        }
    }
}

Open in new window

.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
Marcus Keustermans

8/22/2022 - Mon