Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why we should Use built-in C# native data types vs .NET CTS types ( Use int Not int32, use string not String , use bool not Boolean)
Posted

One of the times you need to use Int32 instead of int would be if you want be double-damn sure that you get a 32-bit int in a 64-bit app (or when reading a data file), or when they redefine int to be equivalent to Int64 instead of Int32. The int used to be the same as Int16.

There are probably other examples, but that's the one that came to mind first.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 19-Mar-12 21:05pm    
"They" are not really supposed to redefine them... however... who knows?
--SA
#realJSOP 21-Mar-12 6:15am    
In VS 1.51, an int was 16-bits. In a later version (I don't know which version this happened), it was made equivalent to an Int32 (but you could still use int as your type definition). At some point, int will be an Int64, probably when/if we ever see 128-bit operating systems.
Sergey Alexandrovich Kryukov 21-Mar-12 21:09pm    
I know, I know. I want to emphasize the paradigm shift in .NET: C approach was focus on platform-dependent types, .NET - on platform-independent. You know that for two 64-bit targets int is 32-bit, exactly as in x86. That is the difference. A 128-bit integers will be added without replacing any other existing types.

A point?
--SA
o reason, really - it is just tidier.
int is just syntactic sugar for int32,
bool
works the same as Boolean

It just makes the code slightly more readable, and more compatible with (for example) C and C++

If your company rules don't prevent it, you can use whichever you want - just try not to mix them!
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 19-Mar-12 21:04pm    
Agree, a 5.
Just a note: when we prefer int over System.Int32, we do not choose a type. The type "int" is no more then a C# alias for System.Int32. Same goes for uint, byte, sbyte, string, object, etc.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900