I am reviewing some code and I see a large amount of string concatentation but they are all very small strings. Something like this:
public string BuildList()
{
return "A" + GetCount() + "B" + TotalCount() + "C" + AMountLeft()
+ "D" + DaysLeft + "R" + Initials() + "E";
}
I am simplifying it but in total the longest string is about 300 characters and the number of +
are about 20. I am trying to figure out if its worth to convert it to StringBuilder and do something like this:
public string BuildList()
{
var sb = new StringBuilder();
sb.Append("A");
sb.Append(GetCount());
sb.Append("B");
sb.Append(TotalCount());
sb.Append("C");
sb.Append(AmountLeft());
sb.Append("D");
// etc . .
}
I can't see a big difference from testing but wanted to see if there is a good breakeven rule about using StringBuilder (either length of string or number of different concatenations)?