Say I have a StringBuilder object
var sb = new StringBuilder();
And an arbritrary array of strings
var s = new []{"a","b","c"};
Is this the 'quickest' way to insert them into the stringbuilder instance?
sb.Append(string.join(string.empty, s));
Or does StringBuilder have a function I have overlooked?
Edit: Sorry I dont know how many items sb will contain, or how many items may be in each String[].
If you mean by "quickest" most performant than better use:
for(int i = 0; i < myArrayLen; i++)
sb.Append(myArray[i]);
string.Concat(...) should be faster than string.Join("", ...). Also, this depends on what else you're doing with your StringBuilder. If you're only performing a few concatenations then it can be faster not to use it.
More context always helps!
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