简体   繁体   English

为什么Int64.MaxValue返回Long?

[英]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 just an alias for Int64 . long只是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. 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. Int16Int32Int64分别别名为shortintlong Note that the number is how many bits are used to store the value. 请注意,该数字是用于存储该值的位数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 确定Int64变量和Int64.MaxValue之间的差异的最佳方法是什么? - What's the best method of determining the difference between an Int64 variable and Int64.MaxValue? 为什么int32.maxvalue + 1会长时间溢出? - Why does int32.maxvalue + 1 overflow a long? 为什么Int32.MaxValue * Int32.MaxValue == 1? - Why does Int32.MaxValue * Int32.MaxValue == 1? 为什么Int32.MinValue - 1返回Int32.MaxValue? - Why does Int32.MinValue - 1 return Int32.MaxValue? 为什么[float.MaxValue == float.MaxValue + 1]确实返回true? - Why [float.MaxValue == float.MaxValue + 1] does return true? 为什么使用int.MaxValue的数组的分配失败并且分配两个大小为int.MaxValue / 2的数组不会? - Why the Allocation of an array with int.MaxValue fails and the allocation of two arrays with the size int.MaxValue / 2 does not? 为什么“ UInt64 [] arr = new UInt64 [UInt64.MaxValue];”会引发异常? - why does “UInt64[] arr=new UInt64[UInt64.MaxValue];” throw exception? 为什么要使用int.MaxValue-int.MinValue = -1? - Why int.MaxValue - int.MinValue = -1? 为什么.Net实现Random.Next(int,int)要求maxValue> = minValue? - Why does the .Net implementation of Random.Next(int, int) require maxValue >= minValue? 将long.MaxValue转换为int并将float.MaxValue转换为int有什么区别? - What is the difference between casting long.MaxValue to int and casting float.MaxValue to int?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM