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

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -