从学习笔记1,可以看出Console.WriteLine("hi" +3),会隐含调用string.ConCat("hi", 3)
那么,我们推测下面的2个函数完全等同:
public void StringConcat0()
{
Console.WriteLine("hi" + 3);
}
public void StringConcat1()
{
Console.WriteLine(string.Concat("hi", 3));
}反汇编结果如下,证实了我们的推测:
.method public hidebysig instance void StringConcat0() cil managed
{
.maxstack 8
L_0000: ldstr "hi"
L_0005: ldc.i4.3
L_0006: box int32
L_000b: call string [mscorlib]System.String::Concat(object, object)
L_0010: call void [mscorlib]System.Console::WriteLine(string)
L_0015: ret
}
.method public hidebysig instance void StringConcat1() cil managed
{
.maxstack 8
L_0000: ldstr "hi"
L_0005: ldc.i4.3
L_0006: box int32
L_000b: call string [mscorlib]System.String::Concat(object, object)
L_0010: call void [mscorlib]System.Console::WriteLine(string)
L_0015: ret
}





浙公网安备 33010602011771号