Today I was doing another Codegolf challenge over at Codegolf StackExchange, and I tried to do this:
SomeEnum = SomeCondition ? 1 : 2;
but this tells me Cannot convert source type 'int' to target type 'SomeEnum'
, so I tried this instead:
SomeEnum = SomeCondition ? (SomeEnum)1 : (SomeEnum)2;
Which then solved my problem, but to my surprise the first cast here is said to be redundant. My question is: Why do I only need to cast the last integer to SomeEnum
?