The USING keyword in C#: How to clean unnecessary using directives in Visual Studio

The Autodidactic Hacker

Using keyword in C#

There are two ways of using the using keyword in C#:

  1. As a statement
  2. As a directive

Using keyword as a statement

MSDN says the using keyword

Provides a convenient syntax that ensures the correct use of IDisposable objects.

This is also a way of saying that this is the standard way of releasing unmanaged resources. The following is an example of its usage:

Using keyword as a directive

This is the most common usage of the using keyword. The following example shows how using keyword is used to access types in a namespace. This practice of using the using directives to access types in a namespace allows the developer to avoid fully qualifying the type. This save a lot of time and typing.

Another use of using is to create aliases. An excellent discussion on this topic can be found in this Stackoverflow thread.


View original post 163 mots de plus


Laisser un commentaire

Choisissez une méthode de connexion pour poster votre commentaire:


Vous commentez à l'aide de votre compte Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s