So, I looked at ILDASM, checking the .exe file, which looks like this:
int a = 2; Int32 b = 1; if(b == 1) { }
Now the CIL code looks like this:
IL_0005: ldloc.1 IL_0006: ldc.i4.1 IL_0007: ceq IL_0009: ldc.i4.0 IL_000a: ceq IL_000c: stloc.2
I understand that the first b is loaded (which is stored in [1]), then a constant with a value of 1, and then compared. I do not understand why another constant with a value of 0 is loaded and compared until the comparison result is saved.
Since the first comparison should already produce a true value, checking if this value is 0 inverts the result, right?
Now my question is: why is it upside down? I assume this has something to do with the == operator I used, and my theory is that it returns the difference. If this difference is 0, the values ββwill be the same, so the result should be true. But 0 means false, so you need to flip it.
I just can't find anything about this topic, just about operators like == ~ or the like. I hope you can enlighten me :)
Best wishes
Wilsu
PS: This is the full code:
.method private hidebysig instance void Form1_Load(object sender, class [mscorlib] System.EventArgs e) cil managed {
source share