I need to assign constant value in integer (or other data type).
I got "Cannot convert ..." error with the assignment.
Casting doesn't seem to work with "Overflow ..." error.
What's wrong with this?
You've defined too many F
s in the constant. Using 0xFFFFFFFF
the compiler must choose a a storage location that supports a positive value of 0xFFFFFFFF
. The max positive value of an Int32
is instead 0x7FFFFFFF
and hence the compiler correctly errors. The only types which can hold 0xFFFFFFFF
are uint
or one of the 64 bit storages.
To fix this just use Int32.MaxValue
int i32 = Int32.MaxValue;