C# String Concat() Method

Definition
In C#, String.Concat() joins strings into one new string. It does not insert a separator between pieces.
You pass the pieces to join. At least one value is required in normal use. The inputs are not changed. The result is a new string.
Syntax
Pass the pieces to join. Start with this call.
string s = string.Concat("Code", "To", "Fun");
| Call | What it does |
|---|
string.Concat("Code", "To", "Fun") | Joins the pieces into CodeToFun with no spaces. |
This is a static method. For a separator between items, use string.Join.
Library declarations
public static string Concat(string str0, string str1);
public static string Concat(params string[] values);
Parameters
| Parameter | Description |
|---|
| str0 | Required. The first string. |
| str1 | Required. The second string. |
| values | Optional. More strings when you use the params overload. |
Return Value
| Return Value | Description |
|---|
| New string | The joined text. Empty pieces become empty text. |
C# Examples
Example 1 — Join First and Last Name
Build a full name with an explicit space separator between two strings.
using System;
class Program {
static void Main() {
string first = "John";
string last = "Doe";
string fullName = string.Concat(first, " ", last);
Console.WriteLine(fullName);
Console.WriteLine($"first still: {first}");
}
}
John Doe
first still: John
How It Works
- Call the static method.
string.Concat(first, " ", last) joins three pieces in order. - Include the separator. The space is its own argument—Concat does not insert separators automatically.
- Get a new string.
fullName is "John Doe". - Inputs stay unchanged.
first is still "John" because strings are immutable.
Example 2 — Concat an Array (or params)
Pass a string[] or several arguments—both join left to right with no separator between items.
using System;
class Program {
static void Main() {
string[] parts = { "Code", "To", "Fun" };
string glued = string.Concat(parts);
string spaced = string.Concat(parts[0], " ", parts[1], " ", parts[2]);
Console.WriteLine(glued);
Console.WriteLine(spaced);
}
}
How It Works
- Array overload.
Concat(parts) joins every element with nothing between → "CodeToFun". - Add spaces yourself. Pass separators as extra arguments when you need gaps.
- Need commas between items? Prefer string.Join(", ", parts)—built for delimiters.
- Params works the same.
Concat("A", "B", "C") is equivalent to joining those three strings.
Example 3 — Null Becomes Empty
null string arguments are skipped as empty text—safe, but easy to miss when debugging missing words.
using System;
class Program {
static void Main() {
string middle = null;
string result = string.Concat("Hello", middle, "!");
Console.WriteLine(result);
Console.WriteLine($"Length: {result.Length}");
}
}
How It Works
- Pass null in the middle.
middle is null. - Concat substitutes empty.
"Hello" + "" + "!" → "Hello!". - No exception. Unlike some APIs, Concat does not throw on null string args.
- Watch missing text. If a name is unexpectedly blank, check for null inputs—not a printed
"null".
Frequently Asked Questions
Concat() joins strings into one new string with no separator.
Pass the strings to join. Common overloads take two strings or a params array.
A new string with all pieces joined.
No. Strings are immutable. The inputs stay the same.
Use string.Join(separator, values) when you need commas or spaces between items.
About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
9 people found this page helpful