17

Possible Duplicate:
Assuming 32bit ints

So I read somewhere that int equals int32 in c#. Is it true also on 64-bit machines? Should I use int32 just to make sure no one at microsoft decides to change the size of int?

Community
  • 1
  • 1
Faruz
  • 9,909
  • 10
  • 48
  • 66

6 Answers6

28

int is an alias for Int32

long is an alias for Int64

Their sizes will not change, at all, just use whichever one you need to use.

The use of them in your code is in no way related to 32bit and 64bit machines

EDIT: In reference to the comments about Thread Safety. Here is a good question and answers that detail any issues you need to be aware of. Under C# is Int64 use on a 32 bit processor dangerous

Community
  • 1
  • 1
Robin Day
  • 100,552
  • 23
  • 116
  • 167
  • 4
    Actually I believe when it comes to thread synchronization the 32bit and 64bit state will matter, as reading a Int64 on a 32bit processor requires 2 processing operations, rather than just 1, which can be import for thread safety. – Ian Nov 05 '09 at 12:08
  • 2
    @Ian: Atomicity is not guaranteed for int32 reads either in the common language specification. – Tamas Czinege Nov 05 '09 at 12:17
7

On both 32-bit and 64-bit machines:

  • long is 64-bit, it's a synonym for System.Int64.
  • int is 32-bit, it's a synonym for System.Int32.
Michael Damatov
  • 15,253
  • 10
  • 46
  • 71
7

You don't need to worry. An int is an Int32 is a 32-bit signed integer, and that won't change, regardless of the platform that you're using.

See the Microsoft C# spec (section 1.3), the ECMA C# spec (section 8.2.1) and the ECMA CLI spec (section 8.2.2).

LukeH
  • 263,068
  • 57
  • 365
  • 409
3

Integer is 32 bit Long is 64 bit

On both 32 and 64 bit processors

zeocrash
  • 636
  • 2
  • 8
  • 31
2

Simply NO. Types are consistent.

this. __curious_geek
  • 42,787
  • 22
  • 113
  • 137
1

I used Int32 in my first year with .NET (then 1.0). Mostly did it for cross-language readability, as Int32 looks the same in VB as in C#. Looking back, I see this entire concern was silly. Use native types and don't sweat it.

Andriy Volkov
  • 18,653
  • 9
  • 68
  • 83