jimmij jimmij - 1 month ago 4
C# Question

Most efficient way to concatenate strings?

What's the most efficient way to concatenate strings?


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

StringBuilder sb = new StringBuilder();

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

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