Is there a function in C# to quickly convert some collection to string and separate values with delimiter?
For example:
List<string> names –> string names_together = "John, Anna, Monica"
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.
You can use
String.Join. If you have aList<string>then you can callToArrayfirst:In .NET 4 you don’t need the
ToArrayanymore, since there is an overload ofString.Jointhat takes anIEnumerable<string>.In newer versions of .NET different
String.Joinoverloads use different approaches to produce the result. And this might affect the performance of your code.For example, those that accept
IEnumerableuseStringBuilderunder the hood. And the one that accepts an array uses a heavily optimized implementation with arrays and pointers.Results: