Using system; <br/> using system. diagnostics; </P> <p> namespace consoleapplication1 <br/>{</P> <p> Public sealed class Program <br/>{< br/> Public static void main () <br/> {<br/> console. writeline (add ("Pinder", "Hi"); <br/>}</P> <p> Public static string add (Params object [] O) <br/>{< br/> string S = NULL; <br/> for (INT I = 0; I <O. length; ++ I) <br/>{< br/> S + = (string) O [I]; <br/>}< br/> return S; <br/>}</P> <p> Public static string add (Params string [] O) <br/>{< br/> string S = NULL; <br/> for (INT I = 0; I <O. length; ++ I) <br/>{< br/> S + = O [I]; <br/>}< br/> return S; <br/>}</P> <p> Public static string add (string S1, string S2) <br/>{< br/> return S1 + S2; <br/>}< br/>}
. Method public hidebysig static string add (object [] O) di-managed <br/>{< br/>. param [1] <br/>. custom instance void [mscorlib] system. paramarrayattribute ::. ctor () = (01 00 00 00) <br/> // code size 44 (0x2c) <br/>. maxstack 3 <br/>. locals Init ([0] string S, <br/> [1] int32 I, <br/> [2] string CS $1 $0000, <br/> [3] bool CS $4 $0001) <br/> il_0000: NOP <br/> il_0001: ldnull <br/> il_0002: stloc.0 <br/> il_0003: LDC. i4.0 <br/> il_0004: stloc.1 <br/> il_0005: BR. s il_001c <br/> il_0007: NOP <br/> il_0008: ldloc.0 <br/> il_0009: ldarg.0 <br/> il_000a: ldloc.1 <br/> il_000b: ldelem. ref <br/> il_000c: castclass [mscorlib] system. string <br/> il_0011: Call string [mscorlib] system. string: Concat (string, <br/> string) <br/> il_0016: stloc.0 <br/> il_0017: NOP <br/> il_0018: ldloc.1 <br/> il_0019: LDC. i4.1 <br/> il_001a: Add <br/> il_001b: stloc.1 <br/> il_001c: ldloc.1 <br/> il_001d: ldarg.0 <br/> il_001e: ldlen <br/> il_001f: Conv. i4 <br/> il_0020: CLT <br/> il_0022: stloc.3 <br/> il_0023: ldloc.3 <br/> il_0024: brtrue. s il_0007 <br/> il_0026: ldloc.0 <br/> il_0027: stloc.2 <br/> il_0028: BR. s il_002a <br/> il_002a: ldloc.2 <br/> il_002b: Ret <br/>}// end of method program: Add </P> <p>
. Method public hidebysig static string add (string [] O) di-managed <br/>{< br/>. param [1] <br/>. custom instance void [mscorlib] system. paramarrayattribute ::. ctor () = (01 00 00 00) <br/> // code size 39 (0x27) <br/>. maxstack 3 <br/>. locals Init ([0] string S, <br/> [1] int32 I, <br/> [2] string CS $1 $0000, <br/> [3] bool CS $4 $0001) <br/> il_0000: NOP <br/> il_0001: ldnull <br/> il_0002: stloc.0 <br/> il_0003: LDC. i4.0 <br/> il_0004: stloc.1 <br/> il_0005: BR. s il_0017 <br/> il_0007: NOP <br/> il_0008: ldloc.0 <br/> il_0009: ldarg.0 <br/> il_000a: ldloc.1 <br/> il_000b: ldelem. ref <br/> il_000c: Call string [mscorlib] system. string: Concat (string, <br/> string) <br/> il_0011: stloc.0 <br/> il_0012: NOP <br/> il_0013: ldloc.1 <br/> il_0014: LDC. i4.1 <br/> il_0015: Add <br/> il_0016: stloc.1 <br/> il_0017: ldloc.1 <br/> il_0018: ldarg.0 <br/> il_0019: ldlen <br/> il_001a: Conv. i4 <br/> il_001b: CLT <br/> il_001d: stloc.3 <br/> il_001e: ldloc.3 <br/> il_001f: brtrue. s il_0007 <br/> il_0021: ldloc.0 <br/> il_0022: stloc.2 <br/> il_0023: BR. s il_0025 <br/> il_0025: ldloc.2 <br/> il_0026: Ret <br/>}// end of method program: Add </P> <p>
. Method public hidebysig static string add (string S1, <br/> string S2) di-managed <br/>{< br/> // code size 13 (0xd) <br/>. maxstack 2 <br/>. locals Init ([0] string CS $1 $0000) <br/> il_0000: NOP <br/> il_0001: ldarg.0 <br/> il_0002: ldarg.1 <br/> il_0003: call string [mscorlib] system. string: Concat (string, <br/> string) <br/> il_0008: stloc.0 <br/> il_0009: BR. s il_000b <br/> il_000b: ldloc.0 <br/> il_000c: Ret <br/>}// end of method program: Add </P> <p>
The amount of code is getting smaller and smaller.
The first two methods are too many:
. Locals Init ([0] string S, <br/> [1] int32 I, <br/> [2] string CS $1 $0000, <br/> [3] bool CS $4 $0001)
The first type of code is larger because:
Il_000c: castclass [mscorlib] system. String