【发布时间】:2018-10-28 17:57:26
【问题描述】:
当我尝试创建以下变量时:
UInt64 mod32 = (UInt64)(UInt32.MaxValue + 1);
我收到以下错误:'The operation overflows at compile time in checked mode'
我该如何解决/忽略这个问题?
【问题讨论】:
标签: c# compiler-errors numbers
当我尝试创建以下变量时:
UInt64 mod32 = (UInt64)(UInt32.MaxValue + 1);
我收到以下错误:'The operation overflows at compile time in checked mode'
我该如何解决/忽略这个问题?
【问题讨论】:
标签: c# compiler-errors numbers
你应该这样做:
UInt64 mod32 = UInt32.MaxValue + (UInt64)1;
当你做(UInt64)(UInt32.MaxValue + 1)时,程序会先尝试做UInt32.MaxValue + 1,这是错误的原因,然后再转换为UInt64。
【讨论】: