【问题标题】:'The operation overflows at compile time in checked mode' Error'在检查模式下编译时操作溢出'错误
【发布时间】: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


【解决方案1】:

你应该这样做:

UInt64 mod32 = UInt32.MaxValue + (UInt64)1;

当你做(UInt64)(UInt32.MaxValue + 1)时,程序会先尝试做UInt32.MaxValue + 1,这是错误的原因,然后再转换为UInt64

【讨论】:

    猜你喜欢
    • 2012-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-14
    • 1970-01-01
    • 2011-01-24
    • 1970-01-01
    相关资源
    最近更新 更多