LoginSignup
3
0

More than 5 years have passed since last update.

【C#】【自分用メモ】StringBuilderを使用して1,000,000文字高速で格納する

Last updated at Posted at 2018-09-12

研修で作成したものの自分用メモ。
StringBuilderで予めCapacityを指定しておく。
参考:https://dobon.net/vb/dotnet/string/stringbuilder.html

MillionStr.cs
static void Main()
{
    const int LoopCount = 1000000;
    StringBuilder sb = new StringBuilder(LoopCount);
    const string AppendedString = "あ";
    //// ストップウォッチクラス生成
    var sw = new System.Diagnostics.Stopwatch();
    sw.Start();
    for (int i = 0; i < LoopCount; i++)
    {
        sb.Append(AppendedString);
    }
    sw.Stop();
    Console.WriteLine(sw.Elapsed.ToString());
}
3
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0