当前位置:编程学习 > asp >>

关注性能:字符串操作

View Code

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading;
 6 using System.Diagnostics;
 7
 8 namespace CSharpStudy
 9 {
10     class Program
11     {
12         static void Main(string[] args)
13         {
14             Helper.Watch(() =>
15             {
16                 var str = new StringBuilder();
17                 for (var i = 0; i < 100000; i++)
18                 {
19                     str.Append(i);
20                 }
21             });
22             Helper.Watch(() =>
23             {
24                 var str = "";
25                 for (var i = 0; i < 100000; i++)
26                 {
27                     str += i;
28                 }
29             });
30             Helper.Watch(() =>
31             {
32                 var str = "";
33                 for (var i = 0; i < 100000; i++)
34                 {
35                     str += i.ToString();
36                 }
37             });
38         }
39     }
40

 


摘自 学海无涯

补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,