Most efficient way to concatenate strings?

.net, c#, optimization, performance, string

Solution

The `StringBuilder.Append()` method is much better than using the `+` operator. But I've found that, when executing 1000 concatenations or less, `String.Join()` is even more efficient than `StringBuilder`.

StringBuilder sb = new StringBuilder();
sb.Append(someString);

The only problem with `String.Join` is that you have to concatenate the strings with a common delimiter.

Edit: as @ryanversaw pointed out, you can make the delimiter `string.Empty`.

string key = String.Join("_", new String[] 
{ "Customers_Contacts", customerID, database, SessionID });

Problem

What's the most efficient way to concatenate strings?

Original source

Related problems