- using System;
- using System.Text;
- using System.Collections.Generic;
- using System.Diagnostics;
-
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- String str = "";
- StringBuilder sb = new StringBuilder();
-
- Stopwatch sw = new Stopwatch();
- sw.Start();
-
- for (int i = 0; i < 100000; i++)
- {
- str += "a";
- }
-
- sw.Stop();
- Console.WriteLine("String結合:" + sw.Elapsed + "秒");
-
- str = null;
-
- sw.Restart();
-
- for (int i = 0; i < 100000; i++)
- {
- sb.Append("a");
- }
-
- sw.Stop();
- Console.WriteLine("StringBuilder結合:" + sw.Elapsed + "秒");
-
- Console.ReadLine();
-
- }
- }
- }
|