Hi, I've read that the StringBuilder type has a limit (the default is 16 characters), and when you append some text to it, beyond its limit, a new instance is created with a higher limit and the data is copied to it. I tried that using the following code :
StringBuilder test = new StringBuilder("ABCDEFGHIJKLMNOP",16);
test.Append("ABC");
And the CIL generated for that was :
.maxstack 3
.locals init (class [mscorlib]System.Text.StringBuilder V_0)
IL_0000: nop
IL_0001: ldstr "ABCDEFGHIJKLMNOP"
IL_0006: ldc.i4.s 16
IL_0008: newobj instance void [mscorlib]System.Text.StringBuilder::.ctor(string, int32)
IL_000d: stloc.0
IL_000e: ldloc.0
IL_000f: ldstr "ABC"
IL_0014: callvirt instance class [mscorlib]System.Text.StringBuilder [mscorlib]System.Text.StringBuilder::Append(string)
IL_0019: pop
IL_001a: ret
Setting the limit to, say, 32 :
StringBuilder test = new StringBuilder("ABCDEFGHIJKLMNOP",32);
test.Append("ABC");
Generated exactly the same IL code. What I expect is creating a new instance in the first case, and changing the value of the instance in the second case, which obviously didn't happen, any clue why?