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. In this article we will go one step further and understand how to make code readable by creating namespace alias qualifier in C#.
Namespace Alias Qualifier in C#:
Let’s take a look at the simple example below and try to 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. In the code below, I have created the SIO as an alias name for System.IO namespace. Hence, my code is more readable as I can easily identify File.Exist() belongs to which namespace on the go (without navigating to its reference).
– Article ends here –