Rosmarine Popcorn
Rosmarine Popcorn

Reputation: 10967

Why does Int64.MaxValue return a Long?

Huh that's ironic ,while playing around today i wondered if a can Increase Int64.MaxValue on some way ,and just founded out that Int64.MaxValue isn't an Int64 but a Long .

Why is that ,does it mean if i store like Int64 myInt = Int64.MaxValue; than myInt will be still an Int or it will become a Long ,what's the purpose of storing a Long Instead of Int64 at this Field .

Upvotes: 5

Views: 1955

Answers (6)

jason
jason

Reputation: 241701

From the language specification:

The members of a simple type correspond directly to the members of the struct type aliased by the simple type:

• The members of long are the members of the System.Int64 struct.

You can see additional aliases in §3.4.2.

And from 4.1.4:

C# provides a set of predefined struct types called the simple types. The simple types are identified through reserved words, but these reserved words are simply aliases for predefined struct types in the System namespace, as described in the table below.

Reserved word Aliased type
long          System.Int64

Upvotes: 3

Kirill Polishchuk
Kirill Polishchuk

Reputation: 56182

long is a synonym of Int64

Reference: http://msdn.microsoft.com/en-us/library/ctetwysk(v=VS.100).aspx

Upvotes: 9

Steve Rowbotham
Steve Rowbotham

Reputation: 2868

long is just an alias for Int64. See here.

Upvotes: 3

Corey Ogburn
Corey Ogburn

Reputation: 24739

There's Int16, Int32, and Int64 that are aliased to short, int, and long respectively. Note that the number is how many bits are used to store the value.

Upvotes: 0

JohnD
JohnD

Reputation: 14767

Int64 is a long:

        Type t1 = typeof(Int64);
        Type t2 = typeof(long);
        bool same = t1.Equals(t2);  // true

Check out MSDN:

http://msdn.microsoft.com/en-us/library/ya5y69ds.aspx

Upvotes: 2

Ekk
Ekk

Reputation: 5715

Because Int64 and long are same type.

Int64 = long    
Int32 = int    
Int16 = short

Upvotes: 16

Related Questions