Share via


Namespace Aliases in C#

The C# language allows developers to create aliases for lengthy fully qualified names or class names. This can come in handy if there is a long namespace or class name that you do not want to have to keep typing out each time. It is also a useful tool to resolve namespace clashes within your code when identical types are imported into your code base.

To accomplish this you can employ the using keyword in C#. The alias lives within the scope of the namespace it Is declared in. When the code compiles, a token is created for the fully qualified name and the alias is then in effect.

For example, the following code snippet will declare an alias:

using diag = System.Diagnostics.Tracing;

The image below displays how to fully declare and use the alias:

References