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