Here are a few statements ifand how they switch to IL:
ldc.i4.s 0x2f var i = 47;
stloc.0
ldloc.0 if (i == 47)
ldc.i4.s 0x2f
bne.un.s L_0012
ldstr "forty-seven!" Console.WriteLine("forty-seven!");
call Console::WriteLine
L_0012:
ldloc.0 if (i > 0)
ldc.i4.0
ble.s L_0020
ldstr "greater than zero!" Console.WriteLine("greater than zero!");
call Console::WriteLine
L_0020:
ldloc.0 bool b = (i != 0);
ldc.i4.0
ceq
ldc.i4.0
ceq
stloc.1
ldloc.1 if (b)
brfalse.s L_0035
ldstr "boolean true!" Console.WriteLine("boolean true!");
call Console::WriteLine
L_0035:
ret
One thing to note: IL instructions are always "opposite." if (i > 0)converts to something that effectively means "if i <= 0, and then jumps over the block body if."
source
share