once...then it loops through each of the values that get returned by the call
mezoid
2009-08-16 09:44:12
once...then it loops through each of the values that get returned by the call
Short answer: Once
Long answer:
The code gets compiled into the following IL. You can try it yourself by compiling the C# file and then opening it in ILDASM (distributed with Visual Studio) or .NET Reflector (which can show the disassembled code in many languages and has tooltips for IL instructions with detailed description).
L_0008: ldloc.0
L_0009: callvirt instance string [mscorlib]System.String::ToLowerInvariant()
L_000e: stloc.2
L_000f: ldc.i4.0
L_0010: stloc.3
L_0011: br.s L_0021
L_0013: ldloc.2
L_0014: ldloc.3
L_0015: callvirt instance char [mscorlib]System.String::get_Chars(int32)
L_001a: stloc.1
L_001b: nop
L_001c: nop
L_001d: ldloc.3
L_001e: ldc.i4.1
L_001f: add
L_0020: stloc.3
L_0021: ldloc.3
L_0022: ldloc.2
L_0023: callvirt instance int32 [mscorlib]System.String::get_Length()
L_0028: clt
L_002a: stloc.s flag
L_002c: ldloc.s flag
L_002e: brtrue.s L_0013
The actual loop condition is checked on lines L_0021 to L_002c and then there a jump at line L_002e which is executed if not all characters are processed yet. Note that it jumps to L_0013 which is after the ToLowerInvariant call.