What is the use of Using Statement

 Posted by Bharathi Cherukuri on 2/2/2012 | Category: ASP.NET Interview questions | Views: 2438 | Points: 40

Using statement is used similar to finally block that is to dispose the object.
It declares that you are using a disposable object for a short period of time.
Once the using block ends,the CLR releases the corresponding object immediately by calling its dispose() method.


//Write code to allocate some resource

//List the allocated resource in a comma-separated list inside
//the parenthesis of the using block

//use the allocated resource

//Here dispose() method is called for all the object referenced without writing any additional code.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response