Is there a reason not to use aliases in the System namespace?

I've always used String instead of string and Int32 instead of int. Mainly because it's all a class, so I like to maintain consistency and treat so called "primitives" like any other class / object.

I just saw an article on coding standards that mentioned "Always use C # predefined types, not aliases in the systems namespace".

He didn't say why.

0


a source to share


3 answers


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



So, pick one and be consistent.

+1


a source


There is no reason that could affect the behavior or performance of your application. This is the recommended leadership style - and as with all styles, you can ignore it if you like. Almost all OSS and corporate style policies will dictate that you need to use aliases - so keep that in mind.



0


a source


There is no technical reason to use either option. Both are identical in terms of the generated IL.

However, the biggest reason is the consistency and maintainability of others. Using "string", "int", "double", etc. More expected and therefore more convenient.

Also, if you don't have a System, it's much nicer to type "int" than "System.Int32" all the time ...

0


a source







All Articles