The following code prints UInt32
:
var myUint = 1U;
Console.WriteLine(myUint.GetType().Name);
As per this SO answer I wanted to see what would happen if you try to use the U
literal suffix with a compile-time negative number. This code (changing1U
to -1U
) prints Int64
(long
):
var myUint = -1U;
Console.WriteLine(myUint.GetType().Name);
I thought it would just be a compile time error, but instead returns a long
with the value -1
- what is going on? Why does the compiler do this??