Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 5th, 2006, 12:54 PM   #1
hoffmandirt
Hobbyist Programmer
 
hoffmandirt's Avatar
 
Join Date: Jul 2005
Location: PA
Posts: 125
Rep Power: 4 hoffmandirt is on a distinguished road
Send a message via AIM to hoffmandirt
.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.
hoffmandirt is offline   Reply With Quote
Old May 5th, 2006, 2:54 PM   #2
MisterPoppy
Newbie
 
Join Date: Apr 2006
Location: Sweden
Posts: 13
Rep Power: 0 MisterPoppy is on a distinguished road
Correct me if I'm wrong. But I think that "System.Int32" is the same thing as just "int".
MisterPoppy is offline   Reply With Quote
Old May 5th, 2006, 3:02 PM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
"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."
Infinite Recursion is offline   Reply With Quote
Old May 5th, 2006, 3:34 PM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:29 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC