c# - Does StringBuilder use more memory than String concatenation? -


i know obvious performance advantage using stringbuilder in c#, memory difference like?

does stringbuilder use more memory? , side note, stringbuilder differently makes faster?

short answer: stringbuilder appropriate in cases concatenating arbitrary number of strings, don't know @ compile time.

if do know strings you're combining @ compile time, stringbuilder pointless don't need dynamic resizing capabilities.

example 1: want combine "cat", "dog", , "mouse". 11 characters. allocate char[] array of length 11 , fill characters these strings. string.concat does.

example 2: want join unspecified number of user-supplied strings single string. since amount of data concatenate unknown in advance, using stringbuilder appropriate in case.


Comments

Popular posts from this blog

SAP Web Service from .NET via WCF -

Optimized Line drawing in QT -

datetime - str to time in python -