How can I join int to a character-separated string in .NET?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
In .NET, the normal way to join integers into a separator-delimited string is string.Join. You usually do not need a manual loop, and you do not need to convert every number yourself unless you want custom formatting.
The Simplest Approach
If you already have an int[], List<int>, or another numeric sequence, string.Join handles the concatenation directly.
The output is:
Even though the separator is described as a character in everyday language, the API usually accepts a string separator such as ",", "|", or "-".
Joining with Different Separators
A one-character separator is just as straightforward:
This works because string.Join converts each numeric element to text using its standard string representation.
When You Need Custom Formatting
Sometimes plain conversion is not enough. You may want leading zeroes, culture-independent formatting, or hexadecimal output. In that case, format the numbers first and then join the strings.
The output becomes:
This pattern is especially useful when the joined string is consumed by another system that expects a strict representation.
Joining Other Numeric Collections
You are not limited to arrays. string.Join also works well with List<int> and other sequences.
If the values come from LINQ, you can join them directly without forcing a manual loop.
Why Manual Loops Are Usually Unnecessary
A beginner solution often looks like repeated string concatenation in a loop. That works for small inputs, but it is more verbose and easier to get wrong, especially around the final separator.
This is valid code, but string.Join is shorter and clearer for the same job.
Empty Sequences and Null Values
An empty numeric sequence joins to an empty string.
That prints two quotes with nothing between them.
When dealing with nullable numbers such as int?[], decide how you want to handle missing values before joining.
Filtering first avoids accidental blank fields or inconsistent output.
Common Pitfalls
A common mistake is manually calling ToString in a loop when string.Join would already do the job.
Another pitfall is assuming formatting will be consistent across cultures when the output is exchanged with other systems. If formatting matters, use ToString with an explicit format and CultureInfo.InvariantCulture before joining.
Developers also sometimes forget to handle nullable values or empty collections, which leads to unexpected output.
Finally, avoid building large delimited strings with ad hoc concatenation inside loops unless you have a specific reason. The standard library API is clearer and less error-prone.
Summary
- Use
string.Jointo combine integers into a separator-delimited string. - A one-character separator is typically passed as a one-character string such as
","or"|". - Format numbers first with
Selectif you need custom output. - '
string.Joinworks with arrays, lists, and LINQ sequences.' - Manual loops are usually unnecessary unless you have specialized formatting rules.
Related reading
- How can I make Array.Contains case-insensitive on a string array?
- How can I manipulate an array to make the largest number?
- How can I match up permutations of a long list with a shorter list according to the length of the shorter list?
- How can I match up permutations of a long list with a shorter list according to the length of the shorter list?
- How can I limit Parallel.ForEach?
- How can I limit Parallel.ForEach?
- How can I measure thread stack depth?
- How can I multiply all items in a list together with Python?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.