Consider 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 above program is:
Doesn't match
Matches
Why the first comparison fails when unchecked conversion of integer -1 to unsigned integer is 0xFFFFFFFF? (While the second one passes)
Your first comparison will be based on longs … since 0xFFFFFFFF is not an int value 🙂
Try to write
and you will get a
cast is redundantmessage