【发布时间】:2009-05-06 13:28:38
【问题描述】:
我在 .net 程序中目睹了一个奇怪的行为:
Console.WriteLine(Int64.MaxValue.ToString());
// displays 9223372036854775807, which is 2^63-1, as expected
Int64 a = 256*256*256*127; // ok
Int64 a = 256*256*256*128; // compile time error :
//"The operation overflows at compile time in checked mode"
// If i do this at runtime, I get some negative values, so the overflow indeed happens.
为什么我的 Int64 的行为就好像它们是 Int32 一样,尽管 Int64.MaxValue 似乎确认它们使用的是 64 位?
如果相关,我使用的是 32 位操作系统,并且目标平台设置为“任何 CPU”
【问题讨论】:
标签: .net 64-bit math integer-overflow int64