# using keywords in c#

the "using" keyword is used for two different purposes:

1. Resource Management: The "using" keyword is used to automatically dispose of objects that implement the IDisposable interface when they are no longer needed. This is known as automatic resource management or "using blocks."
    

Syntax:

```csharp
using (resource)
{
    // code that uses the resource
}
```

Example:

```csharp
using (var fileStream = new FileStream("example.txt", FileMode.Open))
{
    // code that uses the file stream
}
```

In this example, the "using" block ensures that the "fileStream" object is properly disposed of, even if an exception is thrown or the code execution is interrupted.

1. Namespace Aliasing: The "using" keyword is also used to declare namespace aliases, which allow you to refer to a type or member by its simple name instead of its fully qualified name.
    

Syntax:

```csharp
using alias = namespace;
```

Example:

```csharp
using System.IO;

...

FileStream fileStream = new FileStream("example.txt", FileMode.Open);
```

In this example, the "using" statement allows you to use the "FileStream" type without having to qualify it with its namespace ("[System.IO](http://System.IO)") every time you use it in your code.

Overall, the "using" keyword is an important part of C# and can be used for resource management and namespace aliasing to make your code more concise and efficient.
