using System; using System.Diagnostics; namespace ConsoleApplication1 { public sealed class Program { public static void Main() { Console.WriteLine(Add("pinder","hi")); } public static String Add(params Object[] o) { String s = null; for (int i = 0; i < o.Length; ++i ) { s += (String)o[i]; } return s; } public static String Add(params String[] o) { String s = null; for (int i = 0; i < o.Length; ++i) { s += o[i]; } return s; } public static String Add(String s1, String s2) { return s1 + s2; } } } .method public hidebysig static string Add(object[] o) cil managed { .param [1] .custom instance void [mscorlib]System.ParamArrayAttribute::.ctor() = ( 01 00 00 00 ) // Code size 44 (0x2c) .maxstack 3 .locals init ([0] string s, [1] int32 i, [2] string CS$1$0000, [3] bool CS$4$0001) IL_0000: nop IL_0001: ldnull IL_0002: stloc.0 IL_0003: ldc.i4.0 IL_0004: stloc.1 IL_0005: br.s IL_001c IL_0007: nop IL_0008: ldloc.0 IL_0009: ldarg.0 IL_000a: ldloc.1 IL_000b: ldelem.ref IL_000c: castclass [mscorlib]System.String IL_0011: call string [mscorlib]System.String::Concat(string, string) IL_0016: stloc.0 IL_0017: nop IL_0018: ldloc.1 IL_0019: ldc.i4.1 IL_001a: add IL_001b: stloc.1 IL_001c: ldloc.1 IL_001d: ldarg.0 IL_001e: ldlen IL_001f: conv.i4 IL_0020: clt IL_0022: stloc.3 IL_0023: ldloc.3 IL_0024: brtrue.s IL_0007 IL_0026: ldloc.0 IL_0027: stloc.2 IL_0028: br.s IL_002a IL_002a: ldloc.2 IL_002b: ret } // end of method Program::Add .method public hidebysig static string Add(string[] o) cil managed { .param [1] .custom instance void [mscorlib]System.ParamArrayAttribute::.ctor() = ( 01 00 00 00 ) // Code size 39 (0x27) .maxstack 3 .locals init ([0] string s, [1] int32 i, [2] string CS$1$0000, [3] bool CS$4$0001) IL_0000: nop IL_0001: ldnull IL_0002: stloc.0 IL_0003: ldc.i4.0 IL_0004: stloc.1 IL_0005: br.s IL_0017 IL_0007: nop IL_0008: ldloc.0 IL_0009: ldarg.0 IL_000a: ldloc.1 IL_000b: ldelem.ref IL_000c: call string [mscorlib]System.String::Concat(string, string) IL_0011: stloc.0 IL_0012: nop IL_0013: ldloc.1 IL_0014: ldc.i4.1 IL_0015: add IL_0016: stloc.1 IL_0017: ldloc.1 IL_0018: ldarg.0 IL_0019: ldlen IL_001a: conv.i4 IL_001b: clt IL_001d: stloc.3 IL_001e: ldloc.3 IL_001f: brtrue.s IL_0007 IL_0021: ldloc.0 IL_0022: stloc.2 IL_0023: br.s IL_0025 IL_0025: ldloc.2 IL_0026: ret } // end of method Program::Add .method public hidebysig static string Add(string s1, string s2) cil managed { // Code size 13 (0xd) .maxstack 2 .locals init ([0] string CS$1$0000) IL_0000: nop IL_0001: ldarg.0 IL_0002: ldarg.1 IL_0003: call string [mscorlib]System.String::Concat(string, string) IL_0008: stloc.0 IL_0009: br.s IL_000b IL_000b: ldloc.0 IL_000c: ret } // end of method Program::Add 可见代码量越来越小. 前两种方法多了: .locals init ([0] string s, [1] int32 i, [2] string CS$1$0000, [3] bool CS$4$0001) 第一种代码量更大,是因为多了: IL_000c: castclass [mscorlib]System.String