Namespace Alias Qualifier in C#

In this article, I would like to introduce one of the essential features “Namespace Alias Qualifier” that makes your code more readable. If you are a C# developer, you already know about ‘using’ directive and its purpose. In general, using directive allows the use of types in a namespace so that you do not have to qualify the use of a type in that namespace. This article will go one step further and understand how to make code readable by creating a namespace alias qualifier in C#.

Namespace Alias Qualifier in C#:

Let’s take a look at the simple example below and understand the significance of creating namespace aliases. In Visual Studio, we use F12 to find out the method definition/reference.

Instead of navigating to the reference via context menu/f12, create the namespace alias. I have created the SIO as an alias name for the System.IO namespace in the code below. Hence, my code is more readable as I can quickly identify File.Exist() belongs to which namespace on the go (without navigating to its reference).

– Article ends here –

If you have any questions, please feel free to share your questions or comments on the comment box below.

Share this:
We will be happy to hear your thoughts

      Leave a reply