The C# programming language's using statement makes a call to the Dispose method More Automatic, by simplifying the code that you must write to create and clean up an object.
The using statement obtains one or more resources, executes the statements that you specify, and then disposes of the object.
Note: That the using statement is only useful for objects with a lifetime that does not extend beyond the method in which the objects are constructed.
Imp – Use of ‘Using ‘ block requires the
class Resource :IDisposable
public void Dispose()
// Write code
private void btn_UsingMyth_Click(object sender, EventArgs e)
#region Approach 1
Resource theInstance = null;
theInstance = new Resource();
if (theInstance != null) theInstance.Dispose();