So I was going through some older code at work and came across this:
using Int16 = System.Int16;
using SqlCommand = System.Data.SqlClient.SqlCommand;
I have never seen a Namespace Declaration use an ‘=’ before. What’s the point of using it? Are there any benefits declaring things this way?
What else strikes me as odd is the fact that they even bothered declaring Int16. Doesn’t visual studio know what an Int16 is just by typing it out?
The first line makes… erm… little sense, but it’s not a namespace import; it is a type alias. For example,
intis an alias forInt32. You are perfectly free to create your own aliases as you show in your example.For example, let’s say you have to imported namespaces with two types with the same name (
System.Drawing.PointandSystem.Windows.Pointcome to mind…). You can create an alias to avoid fully qualifying the two types n your code.