Using statement is used to work with an object in C# that inherits IDisposable interface.
IDisposable interface has one public method called Dispose that is used to dispose off the object. When we use Using statement, we don't need to explicitly dispose the object in the code, the using statement takes care of it. For eg.
Using (SqlConnection conn = new SqlConnection())
When we use above block, internally the code is generated like this
SqlConnection conn = new SqlConnection()
// calls the dispose method of the conn object
Using statement make the code more readable and compact.
For more details read http://www.codeproject.com/KB/cs/tinguusingstatement.aspx
Asked In: Many Interviews |