你所在位置:首页C#.net开发 → foreach与for的性能比较

foreach与for的性能比较

发布时间:2019-06-12

 

1 string[] strings = new string[] { "str1", "str2", "str3", "str4", "str5", "str6" };

2             foreach (string s in strings)

3             {

4                 textBox1.AppendText(s + " ");

5             }

IL:

01             foreach (string s in strings)

02 000000e0  nop 

03 000000e1  mov         eax,dword ptr [ebp-44h] 

04 000000e4  mov         dword ptr [ebp-50h],eax 

05 000000e7  xor         edx,edx 

06 000000e9  mov         dword ptr [ebp-54h],edx 

07 000000ec  nop 

08 000000ed  jmp         00000136                       //jmp to J1

09 000000ef  mov         eax,dword ptr [ebp-54h] 

10 000000f2  mov         edx,dword ptr [ebp-50h] 

11 000000f5  cmp         eax,dword ptr [edx+4] 

12 000000f8  jb          000000FF         //低于"1个字节全是1"跳转 

13 000000fa  call        65C86690         //地址如此之大,应该是个外部call

14 000000ff  mov         eax,dword ptr [edx+eax*4+0Ch] 

15 00000103  mov         dword ptr [ebp-48h],eax 

16             {

17 00000106  nop 

18                 textBox1.AppendText(s + " ");
上一篇:C#中实现文字在窗体中从左到右移动
下一篇:C#中实现语音朗读(短信 & 语音短信)