简体   繁体   中英

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 .

Because Int64 and long are same type.

Int64 = long    
Int32 = int    
Int16 = short

long is just an alias for Int64 . See here .

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM