Consider the following program:
static void Main (string[] args) { int i; uint ui; i = -1; Console.WriteLine (i == 0xFFFFFFFF ? "Matches" : "Doesn't match"); i = -1; ui = (uint)i; Console.WriteLine (ui == 0xFFFFFFFF ? "Matches" : "Doesn't match"); Console.ReadLine (); }
The output of the program above:
Doesn't match Matches
Why does the first comparison fail when the unchecked conversion of the integer -1 to an unsigned integer is 0xFFFFFFFF? (As long as the second passes)
source share