This article illustrates the different techniques to concatenate multiple strings in C#.

1. Using String.Concat() method

A simple solution to concatenate multiple strings together is using the String.Concat() method. This is demonstrated below:

Download  Run Code

2. Using String Concatenation Operator

Alternatively, you can also use the traditional string concatenation operator + to concatenate string literals in C#. The compiler internally translates this call into the String.Concat() method.

Download  Run Code

3. Using StringBuilder class

The most efficient solution to concatenate several string values together is using StringBuilder. You can use its Append() method, which is overloaded for all primitive types and generally performs better than the String.Concat() method.

Download  Run Code

 
Quoting Microsoft Docs, “Performance depends on the size of the string, the amount of memory to be allocated for the new string, the system on which your code is executing, and the type of operation. You should be prepared to test your code to determine whether StringBuilder actually offers a significant performance improvement.”

4. Using String Interpolation

Starting with C# 6, one can use String interpolation ($), which provides a convenient syntax for concatenating multiple values together to form a String. The following code example uses string interpolation ($) to concatenate three strings.

Download  Run Code

5. Using String.Format() method

Before C# 6, you can use the String.Format() method in place of string interpolation to concatenate strings in C#, as shown below:

Download  Run Code

6. Using String.Join() method

Another option is to construct a string array from the given strings and pass it to the String.Join() method with an empty string as a delimiter. Here’s what the code would look like:

Download  Run Code

That’s all about concatenating multiple strings in C#.