Ive read a few posts on here and the common suggestion is that stringbuilder is the most efficent if joining over three strings.
all variables are other properties.
public string Summary
{
get
{
return Name.Replace("_", " ") + "<strong>[" + Total + " Devices - " + BadCount + " Offline, " + PendingCount + " Pending]</strong>";
}
}
Im joining four, is a simple concatenation suitable or should I ue stringbuilder? Just seems a little overkill.
Use whatever is most readable in this case. Otherwise it's premature optimization.
I would use String.Format
:
String result = String.Format("{0}<strong>[{1} Devices - {2} Offline, {3} Pending]</strong>"
, Name.Replace("_", " ")
, Total
, BadCount
, PendingCount);
return result;
Even string concatenation is not that bad since strings are stored in the intern pool. So if you use a string a second time it's not created but the already available reference is used.
So as rule of thumb:
String.Format
+
(string concatenation)StringBuilder
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With