> why is the comparison to 0 done twice? Because of the logical negation. Oddly, there's no logical-NOT instruction in IL, so when the C# compiler needs to invert a Boolean on stack, it emits
ldc.i4.0 ceq Not to worry, though - I'm sure it'll be optimized by the JIT'er. - Per ----- Original Message ----- From: "Simon Hewitt" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, February 27, 2003 11:01 AM Subject: [ADVANCED-DOTNET] Compilation question.... > Given this source code > > C# source: > public bool IsIndexed { > get { return (SearchFlags & (int) > AttributeSearchFlags.Index) != 0; } > } > > > why is the comparison to 0 done twice? > > > > Anakrino decompilation: > public bool get_IsIndexed() { > return this.SearchFlags & 1 == 0 == 0; > } > > > ILDASM decompilation: > { > // Code size 15 (0xf) > .maxstack 2 > IL_0000: ldarg.0 > IL_0001: call instance int32 > SimmoTech.ActiveDirectory.ADAttributeSchema::get_SearchFlags() > IL_0006: ldc.i4.1 > IL_0007: and > IL_0008: ldc.i4.0 > IL_0009: ceq > IL_000b: ldc.i4.0 > IL_000c: ceq > IL_000e: ret > } // end of method ADAttributeSchema::get_IsIndexed