35
System.Console.WriteLine(int.MaxValue);

This line gives me the answer of 2,147,483,647 as I have a 32-bit PC.

Will the answer be same on a 64-bit PC?

ElasticCode
  • 7,311
  • 2
  • 34
  • 45
g.revolution
  • 11,962
  • 23
  • 81
  • 107

3 Answers3

56

Yes, the answer will be the same on a 64-bit machine.

In .NET, an int is a signed 32-bit integer, regardless of the processor. Its .NET framework type is System.Int32.

The C# Language specification states:

The int type represents signed 32-bit integers with values between –2,147,483,648 and 2,147,483,647.

silkfire
  • 24,585
  • 15
  • 82
  • 105
Daniel LeCheminant
  • 50,583
  • 16
  • 120
  • 115
27

Yes.

int.MaxValue: 2,147,483,647

Source: https://www.dotnetperls.com/int-maxvalue

Michael
  • 41,989
  • 11
  • 82
  • 128
Unknown
  • 45,913
  • 27
  • 138
  • 182
26

int is just an alias for Int32 - it's defined in the C# specification. Therefore int.MaxValue is the same as Int32.MaxValue which will always be 2147483647.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • 1
    int.MaxValue is guaranteed to return 2147483647 but no such guarantee for Int32.MaxValue: https://blog.paranoidcoding.com/2019/04/08/string-vs-String-is-not-about-style.html – Antao Almada Apr 22 '19 at 14:05