views:

56

answers:

3

Hi,

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.

A: 

There is no reason that would affect the behavior or performance of your application. It is a recommended style guideline - and as with all style guidelines you can ignore it if you see fit. Nearly all OSS and corporate style policies will stipulate that you need to use the aliases - so keep that in mind.

Jonathan C Dickinson
If its merely a styling option then thats great news!
Sir Psycho
Did you mean there is *no* reason that would affect the beahavior or performance of your application?
Jon Skeet
Thanks @Jon - sometimes to easy to miss two keys :).
Jonathan C Dickinson
A: 

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

However, the largest reason is consistency and maintainability by others. Using "string", "int", "double", etc is more expected, and therefore more maintainable.

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

Reed Copsey
It wouldn't be nice if you had to declare 3 variables of type Int16, int and Int64 would it?
Sir Psycho
No. I usually use short, int, and long though ;)
Reed Copsey
+1  A: 

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.

Gary.Ray