What is the use of Using Statement

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

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.

Example:

//Write code to allocate some resource

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

using(...)
{
//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