[英]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 . 哇讽刺的是 ,今天玩的时候我想知道是否可以在某种程度上增加Int64.MaxValue,并且刚刚建立起Int64.MaxValue不是Int64而是Long。
Why is that ,does it mean if i store like Int64 myInt = Int64.MaxValue;
为什么会这样,如果我像
Int64 myInt = Int64.MaxValue;
一样存储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 . 比myInt仍然是一个Int或它将变成Long,在这个领域存储一个Long而不是
Int64
的目的是什么。
Because Int64 and long are same type. 因为Int64和long是同一类型。
Int64 = long
Int32 = int
Int16 = short
long
is a synonym of Int64
long
是Int64
的同义词
Reference: http://msdn.microsoft.com/en-us/library/ctetwysk(v=VS.100).aspx 参考: http : //msdn.microsoft.com/en-us/library/ctetwysk(v = VS.100).aspx
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 theSystem.Int64
struct.•
long
的成员是System.Int64
结构的成员。
You can see additional aliases in §3.4.2. 您可以在§3.4.2中看到其他别名。
And from 4.1.4: 从4.1.4开始:
C# provides a set of predefined struct types called the simple types.
C#提供了一组称为简单类型的预定义结构类型。 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.
简单类型通过保留字标识,但这些保留字只是System命名空间中预定义结构类型的别名,如下表所述。
Reserved word Aliased type
long System.Int64
Int64 is a long: Int64很长:
Type t1 = typeof(Int64);
Type t2 = typeof(long);
bool same = t1.Equals(t2); // true
Check out MSDN: 查看MSDN:
http://msdn.microsoft.com/en-us/library/ya5y69ds.aspx http://msdn.microsoft.com/en-us/library/ya5y69ds.aspx
There's Int16
, Int32
, and Int64
that are aliased to short
, int
, and long
respectively. Int16
, Int32
和Int64
分别别名为short
, int
和long
。 Note that the number is how many bits are used to store the value. 请注意,该数字是用于存储该值的位数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.