1

When I try to create the following variable:

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

and I get the following Error: 'The operation overflows at compile time in checked mode'

How can I fix/ignore this?

  • Possible duplicate of [UInt64 and "The operation overflows at compile time in checked mode"](https://stackoverflow.com/questions/10167219/uint64-and-the-operation-overflows-at-compile-time-in-checked-mode) – mjwills Oct 28 '18 at 20:35

1 Answers1

3

You should do as below:

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

When you do (UInt64)(UInt32.MaxValue + 1) the program will try to do UInt32.MaxValue + 1 first, which is the reason for the error, and then cast to UInt64.

Samvel Petrosov
  • 7,580
  • 2
  • 22
  • 46