![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Hobbyist Programmer
|
.NET Aliases
What are the differences between using System.Int32 and plain old int? I have read some coding standards where it is said that using System.Int32 is bad practice and that I should be using int. I'm not sure why though.
|
|
|
|
|
|
#2 |
|
Newbie
Join Date: Apr 2006
Location: Sweden
Posts: 13
Rep Power: 0
![]() |
Correct me if I'm wrong. But I think that "System.Int32" is the same thing as just "int".
|
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
"Developers with a C/C++ background are often very aware of using the int data type. The reason for this is that the C/C++ language specification does not dictate a fixed size for the int data type. The advantage of this is that the compiler is free to use the most efficient definition of int for a target environment. So for a 16 bit target, int is defined as being 16 bits while for a 32 bit target int is defined as being 32 bits. This efficiency comes at the cost of portability if the code make assumptions about the definition of the int data type.
The C# language also has an int data type, but unlike C/C++ the int data type is clearly defined as being an alias for the System.Int32 data type. See the Microsoft C# language specification sections 4.1.4 and 4.1.5 and the ECMA C# language specification sections 11.1.3 and 11.1.4. Based on this I believe that for C# we are in no danger of the size of int changing. I hope that this alleviates some of the concerns that some developers might have and concerning this issue and rest assured that using int is as safe as using System.Int32. "
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
You can use both, but C# developers generally come from a C++ background and thus prefer using int. It's just a convention, but then again, if everybody follows a convention, we can all read everyone's code.
![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|