Where is the best place to dispose all objects in Code?

 Posted by vishalneeraj-24503 on 12/15/2013 | Category: C# Interview questions | Views: 1038 | Points: 40
Answer:

Finally block is the best place to release all the objects as

Try

{
}
Catch
{
}
Finally
{
//Always check whether object is null or not.
if (con != null)
con.Close();

if(ds != null)
ds.Dispose();


//Here con is our SqlConnection object and ds is our DataSet object.
}


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response