jimmij jimmij - 1 year ago 110
C# Question

Most effecient way to concatenate strings

What's the most efficient way to concatenate strings?

Answer Source

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 });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download