我在一个 .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”。