---
title: "The \"using\" Keyword in C#"  
description: "The \"using\" Keyword in C#"  
author: "Anonymous User"  
published: 2012-11-17  
updated: 2013-02-09  
canonical: https://www.mindstick.com/forum/476/the-using-keyword-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# The "using" Keyword in C#

Hi Guys \
\
[Please tell me](https://www.mindstick.com/forum/33900/please-tell-me-what-are-the-technique-to-content-optimization) the "using" [Keyword in C#](https://www.mindstick.com/forum/253/difference-between-ref-and-out-keyword-in-c-sharp)\
\
thanks\

## Replies

### Reply by Shankar M

The Using [Keyword](https://www.mindstick.com/forum/33572/sql-inner-join-keyword) takes care of freeing the resources automatically associated with the block.

### Reply by AVADHESH PATEL

hi Pravesh

\
The reason for the "using" statement is to ensure that the object is always disposed correctly, and it doesn't require explicit code to ensure that this happens.

```
{ // limits scope of myRes
    MyResource myRes= new MyResource();
    try
    {
        myRes.DoSomething();
    }
    finally
    {
        // Check for a null resource.
        if (myRes!= null)
            // Call the object's Dispose method.
            ((IDisposable)myRes).Dispose();
    }
}
```

\

## We can write above code like this

```
using (MyResource myRes = new MyResource())
{
    myRes.DoSomething();
}
```


---

Original Source: https://www.mindstick.com/forum/476/the-using-keyword-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
