In this rare times when I was writing code that suppose to create large string from smaller chunks and with some non string parameters I was using StringBuilder class of course. Of course because string adding, or string concatenation is very costly when talking about memory utilization. It is because every time you do this:
var text = "Hello world!"+ "n"+ "How are you?";
new string is created for every ‘+’ operation in memory. Not a best way of doing strings creations. StringBuilder
is better because it do not creates strings until you call .ToString
method of StringBuilder
class. Continue reading “Smart string builder”