Skip to content
Discussion options

You must be logged in to vote

@MohammadHamdyGhanem, as mentioned in https://github.com/dotnet/corefx/issues/30363#issuecomment-397050032, there is no way to guarantee that short + short will produce an unsigned value (ushort). As @karelz mentioned

-1 + 0 would silently become ushort.MaxValue.

As for others, operators, it isn't clear where you expect the cast to happen:

ushort = byte + byte should not automatically cast either IMO, because it is not clear if the code wants to first cast to ushort and then add (255+255 = 510), or add with byte limitations (incl. underflow) and then cast to ushort (=254).

The rules today are very clear on what happens, and forcing you to add in an explicit cast ensures you understand…

Replies: 16 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by YairHalberstadt
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1624 on October 16, 2020 07:34.