integer type in C#

This is a discussion on integer type in C# within the C# Programming forums, part of the General Programming Boards category; Hello everyone, 1. C# has integer types, int, int32, int64 and long. In my understanding, int32 is always 32-bit, int64 ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    integer type in C#

    Hello everyone,


    1.

    C# has integer types, int, int32, int64 and long. In my understanding, int32 is always 32-bit, int64 and long are always 64-bit.

    My understanding correct?

    2.

    How about int? Is it 32-bit or 64-bit or depends on how we build application (build as 32-bit? build as 64-bit or any CPU?)


    thanks in advance,
    George

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    129
    He who asks is a fool for five minutes, but he who does not ask remains a fool forever.

    The fool wonders, the wise man asks. - Benjamin Disraeli

    There are no foolish questions and no man becomes a fool until he has stopped asking questions. Charles Steinmetz

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The difference between int and int32 is that int32 is GUARANTEED to be 32 bits, whilst for example a future compiler may decide that int is better off being a 64-bit integer (for example because those are handled FASTER than 32-bit integers in that model of machine).

    So if you have a situation where you want the size to be precise, use int32 or int64. If you just need "some integer that works for 32-bit or larger numbers", then use int.

    The situations where you need defined sizes are when you communicate outside your own unit, for example in sockets, files and such, or talking to hardware registers [unlikely in C#, but as a general rule it applies], modules that are outside of your source control (DLL's for example).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    whilst for example a future compiler may decide that int is better off being a 64-bit integer
    Not in the Net environment, as I understand - there the type lengths are fixed across all compilers, languages and OSes that support Net - ensure that all remote procedure calls (around language, comps, OSes boundaries) will succeded
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks DanFraser, Mats and vart,


    Quote Originally Posted by vart View Post
    Not in the Net environment, as I understand - there the type lengths are fixed across all compilers, languages and OSes that support Net - ensure that all remote procedure calls (around language, comps, OSes boundaries) will succeded
    Question answered.


    regards,
    George

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 02:24 PM
  2. Conversion of pointers to functions
    By hzmonte in forum C Programming
    Replies: 0
    Last Post: 01-20-2009, 01:56 AM
  3. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  4. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 10:42 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21