jimmij jimmij - 3 months ago 10
C# Question

Most effecient way to concatenate strings

What's the most efficient way to concatenate strings?

Answer

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();
sb.Append(someString);

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 });
Comments