A `using` statement is a C# and VB.NET language feature that simplifies deterministic cleanup of disposable resources. Not to be confused with the (C# only) `using` directive (related to namespaces), for which use tag `using-directives`.
It takes an expression that evaluates to an IDisposable
. After that it executes an associated code block. Once the code block exits(both with normal and exceptional exits) it disposes the result of the original expression.
C# Example:
using (StreamReader sr = new StreamReader("c:\file.txt"))
{
//statements
}
VB.NET Example:
Using sr As New StreamReader("c:\file.txt")
'statements
End Using
For Details check: