I know why this is not allowed:
ulong x = 0xFEDCBA9876543210; long y = Int64.MaxValue; Console.WriteLine(x < y);
Obviously, there is no way to implicitly use either an operand for another type or a larger type to perform the comparison.
The operator '<' cannot be applied to operands of type 'ulong' and 'long'.
So this is also invalid (with MinValue
and const
):
ulong x = 0xFEDCBA9876543210; const long y = Int64.MinValue; Console.WriteLine(x < y);
However, this is allowed (instead of MaxValue
):
ulong x = 0xFEDCBA9876543210; const long y = Int64.MaxValue; Console.WriteLine(x < y);
There is no overload <
accepting ulong
and long
, but I saw with Reflector that it silently converts Int64.MaxValue
to ulong
. But this does not always happen. How does it work and what considerations are the cause of this inconsistency?
source share