Skip to content
Discussion options

You must be logged in to vote

This is intended behavior. (Section numbers below refer to C# Language Specification 5.0.)


The reason the ulong/short comparison is invalid is due to this rule: (§4.1.5 / Integral Types)

For the binary +, , *, /, %, &, ^, |, ==, !=, >, <, >=, and <= operators, the operands are converted to type T, where T is the first of int, uint, long, and ulong that can fully represent all possible values of both operands.

Emphasis mine. Not all values of short can be converted to all values of ulong, so the conversion isn't permitted.


The reason the ulong/int.MaxValue and ulong/long.MaxValue comparisons are allowed is due to this one: (§6.1.9 / Implicit constant expression conversions)

An implic…

Replies: 3 comments

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #2015 on October 19, 2020 11:31.