Click here to Skip to main content
15,921,212 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Would I want to implement IDisposable in the SQL class below? I have found articles when to use IDisposable, but none explain it when doing something like below. Thanks!

C#
class main : SQL
{
    void GetTheData()
    {
        DoSQL();
    }
}

class SQL
{
    void DoSQL() 
    {
        using(SQLConnection sq=new SQLConnection()) 
        {
            //SQL Stuff Here
        }    
    }
}
Posted
Updated 9-Mar-10 11:02am
v3

The SQLConnection is created and destroyed inside of a method so I'd say no, don't implement IDisposable. If the connection object was a member of the SQL class then my answer would be different.
 
Share this answer
 
Thanks Jimmanuel. Every article I have read says to implement idisposable when the members are disposable (like if I had a sqlconnection not in using statement or passed via constructor).

I couldn't find a good article showing an example like what I provided.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900