I have an array of integers:
int[] number = new int[] { 2,3,6,7 };
What is the easiest way of converting these into a single string where the numbers are separated by a character (like: "2,3,6,7")?
I’m using C# and .NET 3.5.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As of (at least) .NET 4.5,
is equivalent to:
I see several solutions advertise usage of StringBuilder. Someone complains that the Join method should take an IEnumerable argument.
I’m going to disappoint you 🙂 String.Join requires an array for a single reason – performance. The Join method needs to know the size of the data to effectively preallocate the necessary amount of memory.
Here is a part of the internal implementation of String.Join method: