Breaking

Sunday, September 26, 2021

Confuse your colleagues by using class aliases in C#

C# supports the concept of namespaces aliases for a long time. This allows you to create an alias for long namespaces so you don’t have to specify the whole name every time.

An example:

Did you know that this does not only work for namespaces but also for classes? It is also possible to alias a specific class name.

An example:

This feature could be fun if you start using aliases that match with class names used somewhere else in your codebase. Like in the example above where I assigned the Product class an Order alias. Can’t be any more confusing! So please don’t do this at work and choose a good alias name instead…

No comments:

Post a Comment