Search code examples
c#typesaliases

Is there any reason not to use Aliases in the System namespace?


I've always been used to using String instead of string and Int32 instead of int. Mainly because everything is a class, so I like to keep consistent and treat so called 'primitives' just like every other class/object.

I just saw an article on coding standards where it mentioned "Always use C# predefined types rather than the aliases in the System Namespace."

It didn't say why though.


Solution

  • The types are completely interchangeable, and compile to the same IL. There should be one key rule in your coding standards - if you are editing a shared file, use the same style as the existing code. Nothing is more annoying than trying to fix a file where the style changes every other function.

    So - pick one and be consistent.