How can I handle it from C# front!?
You can use the unchecked
operator for the constant assignment:
uint state = unchecked((uint) -1);
From the C# spec section 7.6.12:
The
checked
andunchecked
operators are used to control the overflow checking context for integral-type arithmetic operators and conversions....
For constant expressions (expressions that can be fully evaluated at compile time), the default overflow checking context is always
checked
. Unless a constant expression is explicitly placed in anunchecked
context, overflows that occur during the compile-time evaluation of the expression always cause compile-time errors.