ILGenerator: how to add a boolean value to the stack

Here's how I can put a float value on the stack (in C #):

ILGenerator gen = method.GetILGenerator();
gen.Emit(OpCodes.Ldc_R4, (float)12.5);

How can I stack a boolean using the Emit method?

+5
source share
1 answer

There is no logical value representation in the evaluation stack. Bool, char, byte, ushort, uint and their signed variants are represented as a 4-byte signed integer (i4).

True

ldc.i4.1

False

ldc.i4.0
+17
source

All Articles