StringBuilder sb = new StringBuilder("test", 4);
sb.Append('\n');
sb.AppendLine("test1");
sb.AppendLine("test2");
sb.AppendLine("test3");
sb.AppendLine("test4");
Run Code Online (Sandbox Code Playgroud)
looking on IL code there is only one newobj line, but I thought there should be more instances of StringBuilder class since it should increase its capacity by creating new object? Or I got it wrong?
// [3 1 - 3 49]
IL_0000: ldstr "test"
IL_0005: ldc.i4.4
IL_0006: newobj instance void [System.Runtime]System.Text.StringBuilder::.ctor(string, int32)
IL_000b: stloc.0 // sb
// [4 1 - 4 17]
IL_000c: ldloc.0 // sb
IL_000d: ldc.i4.s …Run Code Online (Sandbox Code Playgroud)