c# - Unsigned Integer Literal Having Negative Sign -
today came cross strange behaviour, explain why happens?
var x = -1u; // when using -1ul complains though. console.writeline(x.gettype().name); console.writeline(x);
output:
int64
-1
msdn says:
if literal suffixed u or u, has first of these types in value can represented: uint, ulong.
https://msdn.microsoft.com/en-us/library/aa664674%28v=vs.71%29.aspx
your confusion stems interpreting number -1
, followed suffix u
. it's negation -
of number 1u
. number 1u
has type uint
, indicated quote in question. negating uint
produces long
.
Comments
Post a Comment