c# - StringBuilder: AppendFormat and Capacity -
in code try appendformat message length bigger string builder's capacity:
static void main(string[] args) { stringbuilder sb = new stringbuilder(10); sb.appendformat("1234567890123"); // 13 characters console.writeline(sb.capacity); } do know should output (answer @ bottom)?
okay, let's try change code , init stringbuilder capacity, still less string length, example 12:
static void main(string[] args) { stringbuilder sb = new stringbuilder(12); sb.appendformat("1234567890123"); // 13 characters console.writeline(sb.capacity); } so, question is: appendformat double start capacity of stringbuilder if string couldn't appened? if appended string's length should 24 characters, capacity become 48?
output code: 20 & 24
does appendformat double start capacity of stringbuilder if string couldn't appended?
yes -- see here.
whenever append operation causes length of stringbuilder object exceed capacity, existing capacity doubled , append operation succeeds.
Comments
Post a Comment