VS 15.9.3 incorrectly claims that the following typecast is redundant. The use of the typecast does change the behavior. Without the typecast, OverflowException occurs when Int32.MinValue is negated. With the typecast to Int64, it always succeeds without overflow, therefore the typecast is not redundant.
Int32 input32 = Int32.MinValue; // Can also be a parameter or variable, not a constant.
Int64 output64_a = checked(-input32); // Throws OverflowException.
Int64 output64_b = checked(-(Int64)input32); // Does not throw OverflowException but IDE claims "Cast is redundant".
Thanks for investigating.
VS 15.9.3 incorrectly claims that the following typecast is redundant. The use of the typecast does change the behavior. Without the typecast, OverflowException occurs when Int32.MinValue is negated. With the typecast to Int64, it always succeeds without overflow, therefore the typecast is not redundant.
Thanks for investigating.