PROGRAM
StringBuilder sbTest1 = new StringBuilder();
StringBuilder sbTest2 = new StringBuilder();
for (int i = 1; i <= 54; i++)
sbTest1.Append("a");
System.Diagnostics.Debug.WriteLine("sbTest1 =Capacity: "
+ sbTest1.Capacity + ", Length: " + sbTest1.Length);
sbTest2.Append("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa");
System.Diagnostics.Debug.WriteLine("sbTest2 =Capacity: "
+ sbTest2.Capacity + ", Length: " + sbTest2.Length);
OUTPUT
sbTest1 =Capacity: 64, Length: 54
sbTest2 =Capacity: 54, Length: 54
QUESTION
as seen from the output if the string is appeneded to StringBuilder
(sbTest1) from loop the capacity increases by multiple of two and
Lenght would show as many charecters are in the string. If appended
from a statement outside loop as done with sbTest2, would show same
Length and Capacity.
I can not understand the reason as why this behaviour? is this
intentional for some good reason or a bug