Hi folks,
I'm aware of the fact that using a StringBuilder is more efficient than
constantly reassigning a string. For example.
Example A
---------
SringBuilder sb = new StringBuilder();
sb.Append("Some text");
sb.Append(" and some more text");
is more efficient than
Example B
---------
string myString = "Some text";
myString += " some more text";
But what about this.
Example C
---------
StringBuilder sb = new StringBuilder();
sb.Append("Variable = " + myVar + " and that's that.");
vs.
Example D
---------
StringBuilder sb = new StringBuilder();
sb.Append("Variable = ");
sb.Append(myVar);
sb.Append(" and that's that.");
I'm thinking that the concatenation in the Example C does not have the
same overhead as the reassignment in Example B and therefore Example D
is overkill, but I'm prepared to be corrected.
Cheers
Simon