Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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 19-Mar-12 2:45am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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!
  Permalink  
Comments
SAKryukov at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Comments
SAKryukov at 19-Mar-12 21:05pm
   
"They" are not really supposed to redefine them... however... who knows?
--SA
   
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.
SAKryukov at 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

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

  Print Answers RSS
0 OriginalGriff 304
1 Maciej Los 285
2 Sergey Alexandrovich Kryukov 230
3 Shweta N Mishra 186
4 Aajmot Sk 153
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 19 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100