public static void main()
{
    int a=5;
    Console.WriteLine("{0},{1},{2}",a,a,a);    //第二种
    int a=5;
    Object o=a;
    Console.WriteLine("{0},{1},{2}",o,o,o);
}
那种速度快?

解决方案 »

  1.   

    肯定第一种撒至少可以省略Object o=a;
    这一步
      

  2.   

    第一种的IL
    .method private hidebysig static void  Main(string[] args) cil managed
    {
      .entrypoint
      // 代码大小       33 (0x21)
      .maxstack  4
      .locals init (int32 V_0)
      IL_0000:  nop
      IL_0001:  ldc.i4.5
      IL_0002:  stloc.0
      IL_0003:  ldstr      "{0},{1},{2}"
      IL_0008:  ldloc.0
      IL_0009:  box        [mscorlib]System.Int32
      IL_000e:  ldloc.0
      IL_000f:  box        [mscorlib]System.Int32
      IL_0014:  ldloc.0
      IL_0015:  box        [mscorlib]System.Int32
      IL_001a:  call       void [mscorlib]System.Console::WriteLine(string,
                                                                    object,
                                                                    object,
                                                                    object)
      IL_001f:  nop
      IL_0020:  ret
    } // end of method Program::Main
    第二种的 IL.method private hidebysig static void  Main(string[] args) cil managed
    {
      .entrypoint
      // 代码大小       25 (0x19)
      .maxstack  4
      .locals init (int32 V_0,
               object V_1)
      IL_0000:  nop
      IL_0001:  ldc.i4.5
      IL_0002:  stloc.0
      IL_0003:  ldloc.0
      IL_0004:  box        [mscorlib]System.Int32
      IL_0009:  stloc.1
      IL_000a:  ldstr      "{0},{1},{2}"
      IL_000f:  ldloc.1
      IL_0010:  ldloc.1
      IL_0011:  ldloc.1
      IL_0012:  call       void [mscorlib]System.Console::WriteLine(string,
                                                                    object,
                                                                    object,
                                                                    object)
      IL_0017:  nop
      IL_0018:  ret
    } // end of method Program::Main
      

  3.   

    第一种 需要把三个 a 都装箱第二种 只需要把a装到o里面