Multiple StringBuilder.Append calls vs. single .Append with inner string concat

2014-03-20T16:03:52

What is the best practice when using string builders in .NET regarding multiple calls of the .Append method vs. a single call to .Append while concatenating its parameters?

sb.Append(name).Append("; ");

vs.

sb.Append(name + "; ");

Is there any performance penalty when using one over the other? The second variant might in some cases be more readable (and is shorter to write).

Will doing such simple string concatenation of short strings nullify the performance/memory gains of using a string builder?

Copyright License:
Author:「knittl」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/22526864/multiple-stringbuilder-append-calls-vs-single-append-with-inner-string-concat

About “Multiple StringBuilder.Append calls vs. single .Append with inner string concat” questions

What is the best practice when using string builders in .NET regarding multiple calls of the .Append method vs. a single call to .Append while concatenating its parameters? sb.Append(name).Append(...
According to Netbeans hint named Use chain of .append methods instead of string concatenation Looks for string concatenation in the parameter of an invocation of the append method of StringBuild...
I have a piece of code that look follows this pattern , var stringBuilder =new StringBuilder( string.Concat(" string", _variable, "another string" , _variable2 ... ); according to some logic do
I found concatenations of constant string expressions are optimized by the compiler into one string. Now with string concatenation of strings only known at run-time, why does the compiler not opti...
It's recommended (PMD rule AppendCharacterWithChar) to use StringBuilder.append(char) instead of StringBuilder.append(String). I agree with that. But if I want to append a (short) string like "='"...
I know that using most of String's methods will return a new string object which is added to the string pool and that the string literals passed as arguments to these methods also are added to the ...
I'm trying to understand what the best practice is and why for concatenating string literals and variables for different cases. For instance, if I have code like this StringBuilder sb = new
I have some code like this: StringBuilder rgba = new StringBuilder(); for (...){ .... rgba.append(value + ", "); } IntelliJ shows me the following warning: string concatenation as argu...
StringBuilder.Append using float is truncating the value. What is it converting to and how can I stop it from truncating? AttributeOrder is type float and I am losing precision when building the ...
It was said that when I use + operator to concat String it later transforms into StringBuilder.append but when I ran Java Decompiler GUI and opened MainClass.class there was public class MainClas...

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.