joyrice

博客园 首页 新随笔 联系 订阅 管理

从学习笔记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(objectobject)
    
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(objectobject)
    
L_0010: call void [mscorlib]System.Console::WriteLine(string)
    
L_0015: ret 
}

 

 

 

 

posted on 2008-08-15 12:04  joyrice  阅读(367)  评论(0)    收藏  举报